...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 #90 Guest 2015-09-23 17:57
Hello There. I found your blog the use of msn. This is an extremely neatly
written article. I'll make sure to bookmark it and return to read more of
your useful information. Thanks for the post. I will certainly return.

Here is my blog post; CIALIS
0 #89 Guest 2015-09-20 10:43
Hi there colleagues, how is all, and what you would lie to say on the topic
of tis article, in my view its really amazing in support of me.

Visit my webpage - coupon cialis
0 #88 Guest 2015-09-19 04:16
Hi there to all, it's in faqct a good for me to visit this web page,it contains
useful Information.

Here iss my webpage :: buy cialis professional
0 #87 Guest 2015-09-18 16:31
I've been browsing online greater than three hours these days, yet I by no means discovered any interesting articloe like yours.
It is pretty price enough forr me. In mmy opinion, if all
web owners and bloggers made excellent content as you did, thee
wweb can be a lot more useful than ever before.

Also visit my blog - cialis 100 mg strength
0 #86 Guest 2015-09-18 12:50
Howdy! This article could not be written much better!
Reading though this article reminds me of my previous roommate!
He always kept talking about this. I am going to forward his post to him.

Pretty sujre he's going tto have a great read. Thanks for sharing!

my web page; cialis bestellen
0 #85 Guest 2015-09-15 19:58
Pretty parft of content. I just stumbled upon your blog and in accession capital to say that I acquire in fact loved accouhnt yourr weblog posts.
Anyway I'll be subscribing oon your augment
and even I achievement you access persistently fast.

My web-site - purchasing cialis usa
0 #84 Guest 2015-09-05 12:16
This is really attention-grabbing, You are an excessively skilled blogger.
I have joined your rrss feed and look forward to in the hunt for more of your excellent post.
Also, I've sshared your sote in my social networks

Have a look at my webpage - cialis buy
0 #83 Guest 2015-08-19 02:00
We are a group of volunteers and starting a new scheme in our community.

Your site offered us with valuable information to work on. You have done a formidable job and our entire community will be grateful to you.

Here is my web site ... cialis 5 mg
0 #82 Guest 2015-08-09 04:25
I really like reading through a post that can make men and women think.
Also, many thanks for permitting me to comment!

my homepage; nevada
board of pharmacy
0 #81 Guest 2015-08-07 15:50
Nice post. I used to be checking continuously this blog and I'm impressed!
Extremely helpful information specifically the final part :
) I handle such information a lot. I was seeking this certain information for a
long time. Thank you and good luck.

Also visit my web site: cialis 20mg prix au maroc
0 #80 Guest 2015-07-15 15:32
Spot on with this write-up, I honestly believe that this web site needs far more attention. I'll probably be
returning to see more, thanks for the info!

Here is my blog post cialis
0 #79 Guest 2015-07-15 07:42
Nice post. I learn something new and challenging on websites I stumbleupon every day.
It's always helpful to read through content from other
authors and practice a little something from other sites.

Feel free to visit my homepage cialis
0 #78 Guest 2015-07-13 01:16
I like reading through a post that can make people think. Also, thanks for permitting me to comment!

Here is my web page ... canadian pharmacy
0 #77 Guest 2015-07-08 15:17
I have read so many posts about the blogger lovers however this paragraph is
really a fastidious post, keep it up.

My webpage :: Cialis
0 #76 Guest 2015-07-07 08:47
What's up, just wanted to say, I enjoyed this blog post.

It was inspiring. Keep on posting!

My website; Cialis
0 #75 Guest 2015-07-06 05:59
Hey I know this is off topic but I was wondering if
you knew of any widgets I could add to my blog that automatically
tweet my newest twitter updates. I've been looking for a plug-in like this for quite some time and was hoping maybe you would have
some experience with something like this. Please let me know if you run into anything.
I truly enjoy reading your blog and I look forward to your new updates.

my web page :: cialis
0 #74 Guest 2015-07-04 13:59
Hi there! I know this is kinda off topic nevertheless
I'd figured I'd ask. Would you be interested in trading links or maybe guest authoring
a blog article or vice-versa? My website discusses a lot of the same topics as yours and I believe we could greatly benefit
from each other. If you're interested feel free to send me an email.
I look forward to hearing from you! Superb blog
by the way!

Here is my page; Cialis
0 #73 Guest 2015-07-01 18:26
Having read this I thought it was extremely enlightening.

I appreciate you taking the time and energy to put this information together.
I once again find myself spending a lot of time both reading
and leaving comments. But so what, it was still worth

Feel free to visit my blog: cialis
0 #72 Guest 2015-06-29 17:32
I seriously love your site.. Pleasant colors & theme. Did you
develop this amazing site yourself? Please reply back as I'm planning
to create my own personal website and would love to learn where you got this from or what the theme is named.
Appreciate it!

Also visit my web blog; www.canadiandrugstore.com
0 #71 Guest 2015-06-28 01:00
Does your site have a contact page? I'm having trouble
locating it but, I'd like to send you an e-mail.
I've got some recommendations for your blog you might be interested in hearing.
Either way, great website and I look forward to seeing it improve over time.

My site; sikis izle

Add comment

Security code