...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 #356 Guest 2016-07-23 03:59
I’ve been exploring for a little bit for any high-quality articles or blogs in this kind of niche.
Luckily I ultimately came across this website. Reading
this info, i am glad I found out what I needed.
Many thanks for posting.

Check out my weblog ... hry casino
0 #355 Guest 2016-07-23 02:27
This is my first time to visit here. I found so many entertaining stuff in your weblog, especially in its
discussion. I guess I am not the only one having all the entertainment here!
Keep up the outstanding work.

my site; hry na registraci zdarma (Jerold)
0 #354 Guest 2016-07-21 05:33
Hi there, after reading this remarkable post i am also
cheerful to share my knowledge here with friends.

Here is my site: Storepro
0 #353 Guest 2016-07-20 04:59
First off I would like to say terrific blog! I had a quick question which I'd like to ask if you do not
mind. I was interested to find out how you center yourself
and clear your thoughts prior to writing. I've had
difficulty clearing my thoughts in getting my ideas out there.
I truly do enjoy writing however it just seems like
the first 10 to 15 minutes are generally wasted simply just trying to figure out how to begin. Any recommendations
or tips? Kudos!

My page ... movie
0 #352 Guest 2016-07-19 18:38
Hi there terrific website! Does running a blog similar to this
require a lot of work? I've no understanding of programming but
I had been hoping to start my own blog in the near future.
Anyhow, should you have any suggestions or tips for new blog owners please share.
I know this is off topic however I simply needed to ask.
Thank you!

Feel free to surf to my webpage doctornorthmelbourne.com.au
0 #351 Guest 2016-07-19 17:13
I just like the helpful information you provide for your articles.
I will bookmark your blog and test once more here frequently.
I'm rather sure I will be told lots of new stuff right here!
Good luck for the following!

Here is my homepage :: seo companies
0 #350 Guest 2016-07-19 06:57
A highly industrialized country, Finland offers its 5.
You can begin with the 18th century Old Vaasa Museum, and change from there.

Nokia the worlds leading manufacturer in mobiles are operating out of Espoo and generate once a year revenue of

Here is my web-site ... Festivals Finland
0 #349 Guest 2016-07-19 04:52
There was obviously a giant, gas-lit Menorah, one huge Christmas tree, and 20 more themed trees which are more than 30 feet tall.

Eight spots were based on the host nation as well as the top seven finishers at
the previous Euro - Basket. This would facilitate you to produce your decisions and organize the requirements, as opposed to
feeling confused and agitated.

Also visit my web page: Helsinki Finland Festival
0 #348 Guest 2016-07-18 19:32
There was obviously a giant, gas-lit Menorah, one huge Christmas tree, and 20 more themed trees which might be
greater than 30 feet tall. You can start using the 1700s Old
Vaasa Museum, and move from there. There may also be
bear watching trips, ATV safari's and trips to Russia in addition to Finnish sauna and
lake swimming to try out, golf, watching birds and fishing.

Have a look at my site - Helsinki Finland Festival
0 #347 Guest 2016-07-18 12:19
It is very interesting topic you’ve published here.
The fact remains I’m not familiar with this,
but I think this is a great chance to find out more about.
Thank you.

Take a look at my web site: sex addict article
0 #346 Guest 2016-07-18 05:10
These are truly wonderful ideas in concerning blogging.
You have touched some pleasant factors here. Any way keep up wrinting.

Look at my page; insurance for iphone 5c
0 #345 Guest 2016-07-15 17:33
Hey! I just wanted to ask if you ever have any trouble
with hackers? My last blog (wordpress) was hacked and I ended up
losing many months of hard work due to no backup.

Do you have any methods to protect against hackers?

My page - levels education
0 #344 Guest 2016-07-12 01:05
Today, while I was at work, my sister stole my apple ipad and tested to see if
it can survive a thirty foot drop, just so she can be a youtube sensation. My apple
ipad is now destroyed and she has 83 views. I know this is entirely off topic but I had to
share it with someone!

Here is my web site ... movie tube now
0 #343 Guest 2016-07-10 13:11
Wһat's up colleagues, іts fantastic piece օf writing rearding educationand ϲompletely defined, қeep it uρ all the timе.

Visit my web-site weekend duffel, Rachelle,
0 #342 Guest 2016-07-10 09:32
The initial weeks were devoted to breaking them inside their home, where we grew to like them and learned all about their personalities, but once they
settled in, they began rampaging down and
up the stairs everyday - and that is nice until they decided
to go "scat cat" and rip the wallpaper, dig for the carpets, Raining
cats And dogs images
spend all night meowing
and crying for that attention. You will need to learn your
cat's nonverbal communication so you are aware of gets hotter has
received enough playing and it's also time and energy to stop.
Tell me more to do with it, how exactly does my dog's diet affect things.
0 #341 Guest 2016-07-07 05:54
" Black became redefined to be a popular, a good affirmation of self. Training last almost a year to two years depending on the career begin entered and degree of educational training. Do you are feeling you're in an advantage or disadvantage from those coming completely from school.

my web page UoN
0 #340 Guest 2016-07-06 09:44
Good post, well written. Thank you. I will be back soon to check out for
updates. Cheers.

My web-site; mark mcilyar
0 #339 Guest 2016-07-05 13:19
Heya i am for the first time here. I came across this board and I
in finding It truly useful & it helped me out a lot.
I am hoping to give one thing back and help others such as you aided me.

Here is my web site :: מנעולן
חירום בירושלים
0 #338 Guest 2016-07-04 19:20
Surely you have got superb ideas here and I love your site!
I’ve bookmarked it making sure that I can come back & continue reading later on.

Here is my website Lakeisha
0 #337 Guest 2016-07-04 17:08
Hello I am so delighted I find your website, I truly found you by mistake, while I was looking on search engines for something else, Anyhow I am here
now and could just like to say cheers for a remarkable post and interesting site.
Please do keep up the truly amazing work.

Visit my blog; Drug Rehab Facilities (drugncc.sonsgriefjourney.com)

Add comment

Security code