...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 #37 Guest 2015-02-23 23:20
Have you ever thought about creating an ebook or guest authoring on other blogs?

I have a blog centered on the same topics you discuss and
would really like to have you share some stories/information. I know my viewers would enjoy your work.
If you're even remotely interested, feel free to shoot me an email.

Also visit my web site ... generic viagra canada
0 #36 Guest 2015-02-14 20:38
Hi there colleagues, nice piece of writing and good arguments commented at this place, I am really enjoying by these.

Here is my website: drugstore online
0 #35 Guest 2015-02-12 19:57
It's truly very difficult in this active life to listen news on Television,
thus I simply use internet for that purpose, and take the most recent news.

Visit my weblog generic viagra
0 #34 Guest 2015-01-28 19:07
This article will assist the internet visitors for setting up new weblog or even a blog from start to end.

Stop by my web-site; online pharmacy for cialis
0 #33 Guest 2015-01-10 00:31
It is appropriate time to make some plans for the future
and it is time to be happy. I've read this post and if I could
I wish to suggest you some interesting things or suggestions.
Maybe you could write next articles referring to this article.
I wish to read more things about it!

Stop by my blog - walgreens drug store
0 #32 Guest 2014-12-16 11:02
Its like you read my mind! You appear to know so much about this, like you wrote the book in it or something.
I think that you can do with a few pics to drive the message home
a bit, but instead of that, this is fantastic blog. An excellent
read. I will certainly be back.

my site; webpage (Aleisha)
-1 #31 Guest 2014-11-12 04:30
Hello,you say how to resolt the question, and it is very usefull.
But I want to know the reason why this question is generated, thanks.
-1 #30 Guest 2014-11-11 07:40
My brother suggested I would possibly like this blog.
He was once totally right. This publish truly made my day.
You can not consider simply how a lot time I had spent for
this info! Thank you!

Here is my blog ... canada viagra generic
-1 #29 Guest 2014-10-23 06:18
May I simply just say what a relief to uncover a person that
really understands what they are discussing on the web.

You certainly realize how to bring an issue to light and make it important.

More and more people really need to check this out and understand this side
of the story. It's surprising you aren't more popular since you definitely possess the gift.

My page :: buy generic cialis in canada
-1 #28 Guest 2014-10-06 07:16
Valuable info. Fortunate me I disscovered yur webite accidentally, and I'm shocked why thiks accident did not happened earlier!
I bookmarked it.

My bloig post Social Media
Marketing Trends
-1 #27 Guest 2014-10-04 11:15
I read this post fully on the topic of the resemblance of
most up-to-date and preceding technologies, it's remarkable article.

My blog post - canadian generic cialis
-1 #26 Guest 2014-09-24 22:27
Good site you've got here.. It's hard to find quality writing like yours these days.
I honestly appreciate people like you! Take care!!

Also visit my web-site ... www.161992up.com
-1 #25 Guest 2014-09-21 03:13
Hello there! This is my first visit to your blog! We are a group of volunteers and starting
a new initiative in a community in the same niche. Your blog provided us useful information to work on. You have done a marvellous job!

[逆輸入SEIKO KINETIC]セイコー メンズ キネティック腕時計 ネイビー ステンレスベルト SKA521P1 [日本製逆輸入SEIKO5 DRESS]セイコー5ドレス メンズ 自動巻き腕時計
オールゴールド ポイントインデックス ゴールドダイアル ゴールドステンレスベルト SNY012J1
[日本製逆輸入SEIKO5]セイコー5 メンズ自動巻き腕時計 ネイビーダイアル シルバーコンビステンレスベルト SNKE85J 送料無料 CASIO カシオ G-SHOCK
Gショック G-LIDE G-ライド GLX-5600C-1 ブラック 黒 メンズ 腕時計 新品 男性用 時計 ウォッチ クォーツ 海外モデル
CASIO G-SHOCK Gショック メンズ 腕時計 新品 時計 多機能 防水 カジュアル ウォッチ
デジタル DW-6900NB-1 ブラック 黒 海外モデル
Metallic Colors メタリックカラーズ母の日 父の日

送料無料カシオ[CASIO]G-SHOCKGA-110RF-9A 海外モデルRastafarian(ラスタファリアン)赤黄緑を基調にしたラスタカラーメンズ 腕時計 男性用
時計 ウォッチ
[逆輸入SEIKO Premier]セイコー プルミエ キネティックダイレクトドライブ メンズ 腕時計 ホワイトダイアル ブラックレザーベルト
送料無料 CASIO OCEANUS Smart Access カシオ オシアナス スマートアクセス OCW-S100B-1AJF メンズ 腕時計 新品 時計 チタン ソーラー電波時計 国内正規品[P5-1023]母の日 父の日 [SEIKO Sportura]セイコー スポーチュラ ホンダレーシングチーム クロノグラフ メンズ腕時計 ブラックダイアル ブラックラバーベルト SNA749P1 [逆輸入SEIKO SPORTURA]セイコー スポーチュラ アラームクロノグラフ メンズ腕時計 ローズゴールド×ブラック ブラックウレタンベルト SNAF28P1

Also visit my web-site - セイコー 腕時計
-1 #24 Guest 2014-09-15 20:14
Have you ever considered about including a little bit more than just your articles?
I mean, what you say is valuable and everything. But think of if
you added some great graphics or video clips to give your posts more, "pop"!
Your content is excellent but with images and clips, this blog
could definitely be one of the greatest in its field.
Awesome blog!

my weblog :: led照明
-1 #23 Guest 2014-09-09 20:41
My spouse and I stumbled over here different page and thought I might as
well check things out. I like what I see so now i am following you.
Look forward to finding out about your web page

my homepage: Cialis
-1 #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
-1 #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
-1 #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
-1 #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

Add comment

Security code