...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 #383 Guest 2016-08-30 18:44
What i do not understood is in reality how you are now not
really much more neatly-favored than you may be right now.
You're very intelligent. You understand thus significantly in terms of this matter, made me individually imagine it from numerous varied angles.
Its like women and men don't seem to be involved unless it is one
thing to do with Girl gaga! Your individual stuffs great.
At all times deal with it up!

my website house
cleanout Services
0 #382 Guest 2016-08-28 04:36
Victor worked for Aspen Commercial Security and has been continually grateful
for the knowledge they have shared with him. Usually a security code is used to open these kinds of locks.
With a very good background to its credit, you
will surely have a rewarding and ingenuous experience with a

Here is my website: מנעולן
0 #381 Guest 2016-08-22 11:00
Ꮇʏ family alwaʏs ssay tҺɑt I am wasting mу time herе at web, exϲept I know I am getting know-how every day by
reading sᥙch nice posts.

Aⅼso visit mу site Anello Bag Offer (Merissa)
0 #380 Guest 2016-08-21 08:50
My brother recommended I would possibly like this blog.
He was once entirely right. This publish actually made my
day. You can not consider just how much time I had spent for this info!
Thank you!

Also visit my web page: movie
0 #379 Guest 2016-08-21 02:05
Wonderful blog! I found it while searching on Yahoo News.
Do you havve any tips on how to get listed in Yahoo News?
I've been trying for a while but I never seem to get there!

Herre is my web site; hello
0 #378 Guest 2016-08-20 14:13
First of all I would like to say wonderful blog!
I had a quick question that I'd like to ask if you don't
mind. I was interested to know how you center yourself and
clear your thoughts before writing. I have had trouble clearing my thoughts in getting my ideas out there.
I do take pleasure in writing but it just seems like the first 10 to 15
minutes are usually wasted simply just trying to figure out how to begin. Any ideas
or hints? Appreciate it!

Feel free to surf to my web page :: dating in kent
0 #377 Guest 2016-08-19 15:38
Good day! Do you know if they make any plugins to help with Search Engine Optimization? I'm
trying to get my blog to rank for some targeted keywords but I'm
not seeing very good gains. If you know of any please share.
Many thanks!

my web page: movietubenow
0 #376 Guest 2016-08-19 11:15
I amm in fɑct pleased to glance at thіs weblog posts ᴡhich cߋntains
plenty of helpful infоrmation, thanks foг providing such data.

Hɑѵе a lkok аt mʏ web paǥe - segway minipro cost (Christen)
0 #375 Guest 2016-08-19 00:22
This is really attention-grabbing, You're an overly professional
blogger. I have joined your feed and stay up for in quest of extra of
your fantastic post. Also, I've shared your website in my social networks

My web blog; dating
0 #374 Guest 2016-08-17 18:13
Very soon this site will be famous amid all blog people, due to it's nice articles or reviews

Look at my blog post :: movietube
0 #373 Guest 2016-08-15 05:45
I read this piece of writing completely regarding the difference of hottest and previous technologies, it's amazing article.

Review my site movietube
0 #372 Guest 2016-08-14 22:01
A person essentially assist to make significantly posts I
would state. This is the very first time I
frequented your web page and thus far? I surprised with the analysis you made to
make this particular publish extraordinary. Fantastic job!

Feel free to surf to my blog movietubenow
0 #371 Guest 2016-08-13 02:21
It's awesome in favor of me to have a web page, which is beneficial in favor of my know-how.

thanks admin

My website movie
0 #370 Guest 2016-08-12 22:19
Greetings from Florida! I'm bored to death at work
so I decided to check out your blog on my iphone during
lunch break. I enjoy the knowledge you present here and can't wait to take a look when I get home.
I'm amazed at how quick your blog loaded on my phone ..

I'm not even using WIFI, just 3G .. Anyhow, good blog!

my web-site ... movietube now
0 #369 Guest 2016-08-12 06:14
Nice post. І leadn ѕomething new aand challenging ߋn websites I stumbleupon оn a daily basis.
It's alwɑys helpful tο read articles frrom οther authors and usse
something from other websites.

Silahkan Cek halaman website Anee hanya untuk dapat Info lebih komplit mengenai www.lexikon-112.de/index.php?title=Benutzer:StephanyTapia9. Suwun
0 #368 Guest 2016-08-09 03:15
Hi there very nice site!! Guy .. Beautiful .. Superb .. I will bookmark your website and take the feeds also?
I'm satisfied to find a lot of useful info here within the post, we need develop more
strategies on this regard, thank you for sharing.
. . . . .

Here is my weblog ... ניהול מוניטין ברכונים
0 #367 Guest 2016-08-07 23:52
Plenty of individuals may benefit from your writing.
Many thanks!

Feel free to surf to my webpage :: Vigrx
Plus Results
0 #366 Guest 2016-08-07 10:46
I simply wanted to thank you a lot more for your incredible website you have developed here.
It is full of helpfulsuggestions for those who are actually interested
in this specific subject, primarily this post.

Also visit my web-site: buy backlinks (xe.Ee)
0 #365 Guest 2016-08-05 09:31
I'm impressed, I have to admit. Rarely do I encounter a blog
that's equally educative and entertaining, and let me tell you, you've hit the nail on the head.
The problem is something that too few men and women are speaking
intelligently about. Now i'm very happy that I found this during my hunt for something concerning this.

Here is my blog post ... bradley Airport car service
0 #364 Guest 2016-08-04 05:01
Hey there, I think your site might be having browser compatibility issues.
When I look at your blog in Safari, it looks fine but when opening in Internet Explorer, it has some overlapping.
I just wanted to give you a quick heads up! Other
then that, awesome blog!

Look at my web page: popcorntime

Add comment

Security code