...because open source matters

  • Increase font size
  • Default font size
  • Decrease font size

Recovering a damaged git repository

E-mail Print


My machine had disk problems. I lost quite a bit of data and it seems I lost one of my git repositories as well.

git log | head
error: Could not read 2e3f651d6fdd1ca7604df1f3b1424a4c67095ccc
fatal: Failed to traverse parents of commit 92a2c1a74048cf8caec7ddd27f943652fab147ac

Analyzing the damage

The ref log apparently is still intact:

$ tail -n 3 .git/logs/refs/heads/master
ba6111ef1ebafac3346f816f36c01bc4af6c2734 03c6b33d82e9e9ec1ecea4985fbe1cca994f44e2 Dirk Tilger  1299783879 +0400 commit: Virgin mono-basic checkin
03c6b33d82e9e9ec1ecea4985fbe1cca994f44e2 2e3f651d6fdd1ca7604df1f3b1424a4c67095ccc Dirk Tilger  1300007389 +0400 commit: Missing efreet dependency
2e3f651d6fdd1ca7604df1f3b1424a4c67095ccc 92a2c1a74048cf8caec7ddd27f943652fab147ac Dirk Tilger  1300007427 +0400 commit: Missing edje dependency

In the list above the first ID is the commit ID, the second ID is the tree ID. The most recent commit is the last one. The commit object 2e3f651d6fdd1ca7604df1f3b1424a4c67095ccc seems damaged:

git log 2e3f651d6fdd1ca7604df1f3b1424a4c67095ccc
fatal: bad object 2e3f651d6fdd1ca7604df1f3b1424a4c67095ccc

The tree object 92a2c1a74048cf8caec7ddd27f943652fab147ac seems intact:

git ls-tree 92a2c1a74048cf8caec7ddd27f943652fab147ac
040000 tree a82504d023fe31e3ed093e58fc4872e5ccd7a4d9    app-portage
040000 tree 0a52ed4638173345b769ec17091db2285849c789    app-text
040000 tree febb17823eb11421f76188d9900c94d6528a6401    app-vim
040000 tree 466e19ae9676334eba999f20e51e6bbea5570933    dev-lang
040000 tree 78dd40b37ebc0cb9ccd59877b08658024416feab    dev-libs
040000 tree 1d60e8774bd1ba9a2170c5507d5357bcfe7bd11d    media-libs
040000 tree 29b1bb0b660a7a7006d2482a9c5703237e2c273f    media-video
040000 tree 5da17094d77e36eb216074117b1fc869aa80b0ce    www-plugins

The commit object 03c6b33d82e9e9ec1ecea4985fbe1cca994f44e2 seems not damaged:

git log --oneline 03c6b33d82e9e9ec1ecea4985fbe1cca994f44e2 | head
03c6b33 Virgin mono-basic checkin
ba6111e Renamed mono ebuild to 9999 version
1fe38af Mono ebuild from the main tree
4835a15 Rename to git ebuild
7ca911f Moonlight ebuild from the main tree
ef843f2 Added odf-converter ebuild from https://bugs.gentoo.org/show_bug.cgi?id=171182
3dce387 g-pypi from my modified pythonhead
1c0ffb8 Compiler plugin for PyLint ( http://www.logilab.org/projects/pylint/ ), a style checking tool for Python.
283897d Awesome. Completion with manual. :
fa38747 vim tasklist greps out TODO and FIXME

The tree object 2e3f651d6fdd1ca7604df1f3b1424a4c67095ccc is damaged:

git ls-tree 2e3f651d6fdd1ca7604df1f3b1424a4c67095ccc
fatal: not a tree object

So to repair this repository all we have to do is to recreate commit 2e3f651d6fdd1ca7604df1f3b1424a4c67095ccc by using the working tree object 92a2c1a74048cf8caec7ddd27f943652fab147ac.


What has been lost is one commit object. In theory we might be able to look for a tree object that is not referenced either by another tree object or a commit object. However, as in my case the last two commits actually had been accepted upstream, all I really need to do is to change the tip of my branch to before the damaged commit.

git branch -l before-efreet 03c6b33d82e9e9ec1ecea4985fbe1cca994f44e2

When I now checkout, I still get an error, because it tries to see what needs merging and so on:

git checkout before-efreet
fatal: unable to read tree 78dd40b37ebc0cb9ccd59877b08658024416feab

This can be fixed by forcing the checkout and with having made a backup of everything just before, nothing will get lost.

git checkout -f before-efreet
Last Updated on Tuesday, 05 July 2011 08:02  


0 #22 Guest 2014-08-26 23:30
Ahaa, its nice conversation regarding this paragraph at this place at this webpage, I have read all that, so at this time me also
commenting at this place.

Feel free to surf to my page - Cialis
0 #21 Guest 2014-08-18 23:14
Touche. Great arguments. Keep up the amazing spirit.

my homepage; prices cialis walmart
0 #20 Guest 2014-08-18 17:05
Thanks for finally talking about >Recovering a damaged git repository
0 #19 Guest 2014-08-15 08:42
Excellent post! We are linking to this particularly great content on our site.
Keep up the good writing.

My weblog; generic cialis
0 #18 Guest 2014-08-12 04:02
What's up friends, how is all, and what you desire to say concerning this paragraph, in my view its truly awesome designed for me.

Review my web blog cialis coupon
0 #17 Guest 2014-08-11 03:05
Yesterday, while I was at work, my sister stole my apple
ipad and tested to see if it can survive a 30 foot drop, just so she
can be a youtube sensation. My iPad is now broken and she has 83 views.
I know this is entirely off topic but I had to share it with

Here is my site :: cialis canada
0 #16 Guest 2014-08-10 05:40
hey there and thank you for your info – I have certainly picked up anything new from
right here. I did however expertise several technical issues using this site, as I experienced to reload the web site a lot of times previous to I could get it to load properly.
I had been wondering if your web host is OK? Not that I'm complaining, but slow loading instances times will sometimes affect
your placement in google and can damage your high quality score if advertising and marketing with Adwords.
Anyway I'm adding this RSS to my e-mail and can look out for much more of your respective
fascinating content. Ensure that you update this again very soon.

My blog: cialis without a prescription
0 #15 Guest 2014-08-09 11:33
Your method of telling all in this piece of writing is in fact
nice, all be capable of easily understand it, Thanks a lot.

Here is my website cialis soft
0 #14 Guest 2014-08-09 10:15
Wonderful post however I was wanting to know if you could write a
litte more on this topic? I'd be very thankful if you could
elaborate a little bit more. Thanks!

Have a look at my homepage: cialis online pharmacy
0 #13 Guest 2014-08-09 06:02
Do you suffer from KIDNEY DISEASE? Do you know that,
according to latest researches, DIALYSIS IS NOT NECESSARY?
A friend of mine got off dialysis (stage 5 CKD) and healed his
kidney. Take a look: www.facebook.com/angelique.dubois.3150/posts/1412669305622411

my blog check this out
0 #12 Guest 2014-08-08 21:21
Please let me know if you're looking for a writer for your
blog. You have some really great articles
and I feel I would be a good asset. If you
ever want to take some of the load off, I'd love to write some material for
your blog in exchange for a link back to mine. Please blast me an e-mail if interested.

Feel free to surf to my weblog - cialis for sale
0 #11 Guest 2014-08-07 18:19
I will right away grasp your rss feed as
I can not to find your e-mail subscription link or e-newsletter service.
Do you've any? Please allow me realize so that I may just subscribe.

Here is my web blog cialis for women
0 #10 Guest 2014-07-25 00:55
If you are going for finest contents like myself, simply visit this website all the
time as it offers quality contents, thanks

My web-site; cialis generic
0 #9 Guest 2014-07-22 15:56
Thank you for some other informative web site. Where else could I
get that type of information written in such an ideal method?
I have a project that I am just now running on, and I have been on the glance out for such information.

Check out my blog :: generic
0 #8 Guest 2014-07-22 03:07
Unquestionably believe that which you said. Your favorite justification seemed to be on the internet the easiest thing
to be aware of. I say to you, I certainly get irked while people think about worries that they just do not know about.
You managed to hit the nail upon the top and defined out the whole thing without having side-effects , people could
take a signal. Will probably be back to get more. Thanks

my blog; generic cialis
0 #7 Guest 2014-07-21 12:13
You actually make it seem so easy with your presentation however I in finding this topic to be really one thing that I think I would by no means understand.
It kind of feels too complicated and very huge for me.
I am looking ahead on your next post, I'll try to get the dangle of it!

Stop by my webpage - cialis generic
0 #6 Guest 2014-07-21 09:00
Ce post est vraiment rempli de bon sens

Here is my web site :: sexy (Hellishhealth2072.over-blog.com)
0 #5 Guest 2014-07-13 06:45
For the reason that the admin of this web page is working, no hesitation very quickly it will be well-known, due to its quality contents.

Also visit my blog post; teeth whitening tips
0 #4 Guest 2014-07-11 06:03
Hey just wanted to give you a brief heads up and let
you know a few of the pictures aren't loading properly. I'm
not sure why but I think its a linking issue. I've tried it in two different internet
browsers and both show the same outcome.
[スピード配送]エスニックな色使いのダイヤ柄が連なる、ハンドメイドで作られたバケツ型トートバッグ インポート
天然素材 カゴバッグ風 かごバッグ風 ナチュラル◆Maison Bengal(マイソンベンガル):MEDIUM BEACH BAG[ダイヤ]

素敵なスカーフを張り合わせたかのような上品なキレイめエスニック大柄スカートベアトップチュニックとしても使えるインド綿ボトムス ミディ丈 ひざ下丈 レディース かわいい おしゃれ 通販 楽天◆ラヴィッサンフラワープリントロングスカート [スピード配送]派手色にアニマル柄にストライプまで!エコバッグ。丈夫で軽いリップトップナイロン素材 折り畳み 折りたたみ エコバック ショッピングバッグ 携帯用 ポケッタブル トートバッグ お買い物バッグ eco エコ◆BAGGU(バッグ):Big BAGGU マーケットバッグ 大きな一輪のお花を、甘すぎないフォルムの帽子にのせました。シックなお花の配色でより大人っぽく… レディース UV対策 日焼け
日除け 天然素材 紫外線◆cheer(チアー):ICHIRINローズコサージュラフィアハット
[送料無料]オールシーズン使える綿ニット素材のニット帽。丁寧に編まれたケーブル編みのシンプルデザイン。頭が小さな方におすすめの小さめニットワッチ!サマーニット 綿100% ケーブルニット 帽子◆BAGMATI(バグマティー) コットンニットキャップ シンプルなフラップデザインのスクエア型メッセンジャーバッグ。硬さのある安定したフォルム ユニセックス
男女兼用 レディース カバン 鞄 綿 コットン 厚手 帆布 斜めがけ 斜め掛け◆ボックススクエア キャンバス ショルダーバッグ
[送料無料]独特の厚底フォルムに、滑らかマットな合皮で洗練された雰囲気。太めアンクルストラップ付きシューズ レディース 春
夏 婦人靴◆マットスムースフェイクレザー
コロンと丸みのあるフォルムに、華奢なショルダー紐が大人スタイルにも気軽に持てるショルダーバッグ レディース 婦人用 鞄 カバン バッグ BAG ショルダー スタッズ◆プチスタッズフェイクレザーショルダーバッグ [人気商品おすすめ]アンティークヴィンテージを思わせるキラリと光るラメのクロス柄ファブリック。フリル状のウエストが可愛いフレアースカート
ギャザースカート スカート ボトムス レディース◆MIMIMEMETE(ミミメメット):ラメ クロス ジョーゼット フレアスカート
お札入れカードポケット小銭入れ付きの多収納ミニハンドバッグ ポシェット
BAG レディース 鞄 かばん 肩掛け バッグ レディース かわいい おしゃれ 春 小物
小物 バック◆クラシック2WAYウォレットバッグ[B]

Here is my website ... フィットネス 通販
0 #3 Guest 2014-07-01 05:42
An attentiongrabbing dialogue is worth comment. I believe that you must write extra on this subject, it won't be a taboo topic but typically persons are not enough to speak on such topics. To the next. Cheers dgkfecafkfeddgab

Add comment

Security code