...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 #120 Guest 2015-11-21 12:13
We are a gaggle of volunteers and opening a brand new scheme in our community.
Your website provided us with valuable info to work
on. You've done an impressive task and our entire group will probably be thankful to you.

Feel free to visit my web-site: medexpress2015.com
0 #119 Guest 2015-11-21 05:22
I don't even know how I ended up here, but I thought this post was good.
I don't know who you are but definitely you're going to a famous blogger if you are not already ;) Cheers!

Also visit my webpage :: car insurance naples fl
0 #118 Guest 2015-11-19 12:20
Thanks for the auspicious writeup. It in fact used to be a enjoyment account it.
Look advanced to more delivered agreeable from you!
By the way, how could we keep up a correspondence?

Here is my page :: how does car
insurance work
0 #117 Guest 2015-11-15 10:16
magnificent post, very informative. I wonder why the opposite experts of this
sector don't understand this. You must continue your writing.
I'm sure, you have a great readers' base already!

My site :: Canadian pharmacies mail order tadalafil
0 #116 Guest 2015-11-15 06:59
I am extremely impressed with your writing skills as well as
with the layout on your weblog. Is this a paid theme or did you customize it yourself?
Anyway keep up the excellent quality writing, it is rare to see a great blog
like this one nowadays.

Also visit my page - viagra on internet canadian
0 #115 Guest 2015-11-15 00:54
I absolutely love your blog and find almost all of your post's to
be what precisely I'm looking for. can you offer guest writers to write content available
for you? I wouldn't mind producing a post or elaborating on a few of the subjects you write regarding here.
Again, awesome blog!

Also visit my blog post; Canadian pharmacy ed tablet
0 #114 Guest 2015-11-14 11:26
I absolutely love your website.. Pleasant colors & theme.

Did you build this amazing site yourself? Please reply back as I'm trying
to create my own personal website and want to
learn where you got this from or exactly what the theme is
called. Many thanks!

Also visit my blog :: Buy online medicine
0 #113 Guest 2015-11-14 09:50
 Because of that technology, today blogging is very big business.

Also visit my blog - Aleksandrowicz
0 #112 Guest 2015-11-14 05:19
It's an awesome paragraph in support of all the online visitors; they
will take advantage from it I am sure.

Also visit my webpage: cialis from usa pharmacy
0 #111 Guest 2015-11-13 19:44
Very quickly this web page will be famous amid all blog users, due
to it's nice posts

Also visit my web blog :: buy
cialis in canada without a prescription?
0 #110 Guest 2015-11-13 17:26
It is the best time to make a few plans for the long run and it is time to
be happy. I've read this post and if I may
just I desire to suggest you few fascinating issues or suggestions.

Maybe you can write subsequent articles relating to this article.
I desire to read more things approximately it!

Here is my homepage - price
of viagra in drugstore in canada
0 #109 Guest 2015-11-13 11:51
Thanks for some other informative site. The place else could I get that
kind of information written in such a perfect approach?
I have a project that I'm simply now running on, and
I've been at the glance out for such information.

Stop by my web site :: what is the cost of cialis at walmart?
0 #108 Guest 2015-11-13 05:14
Fantastic beat ! I would like to apprentice at the same time as you amend your web site, how could i subscribe for a weblog web
site? The account aided me a acceptable deal. I were a little bit familiar of this your broadcast offered brilliant clear idea

my blog Canadian pharmacy viagra super active
0 #107 Guest 2015-11-12 18:14
If you want to get much from this post then you have to apply such techniques to your won web site.

Have a look at my blog post; Ciala coupons
0 #106 Guest 2015-11-12 17:27
Excellent site you've got here.. It's difficult to find high quality writing like yours nowadays.
I seriously appreciate people like you! Take care!!

Visit my webpage ... Online daily use cialis
0 #105 Guest 2015-11-12 13:31
I am not sure where you're getting your information,
but good topic. I needs to spend some time learning much more or understanding more.
Thanks for great info I was looking for this info for my

Feel free to visit my weblog - Buy cialis with percription
0 #104 Guest 2015-11-12 08:54
Thank you for the good writeup. It in fact
was a amusement account it. Look advanced to far added agreeable from you!
By the way, how can we communicate?

my web site ... Cheapcialisonlineusa.com
0 #103 Guest 2015-11-10 23:19
Its such as you learn my mind! You seem to grasp a lot about this,
like you wrote the e book in it or something. I think that you just could do with
a few p.c. to force the message home a little bit, but other than that, this
is fantastic blog. A great read. I'll definitely be back.

Here is my website :: bayin cialis from canada
0 #102 Guest 2015-11-09 19:41
I every time spent my half an hour to read this website's content daily along with a mug of coffee.

my website - viagra tablets in pollachi price
0 #101 Guest 2015-11-09 10:19
I am regular visitor, how are you everybody?
This paragraph posted at this web site is really fastidious.

My blog: cialis coupon 2015

Add comment

Security code