28

I have a local copy of a repository that not longer have any remote associated to it. I'm trying to push this repo into a new remote however everytime I get this message:

error: Could not read 9eefe9305253b2c039a54cbc8aa22f7f8e6e8790
fatal: bad tree object 9eefe9305253b2c039a54cbc8aa22f7f8e6e8790

I read in similar questions here that one way to fix it is retrieving this object from other copies of the repository or doing a hard reset. I can't do any of both since I don't have another copy of this repo.

Is there a way to simply remove this commit or some other kind of solution that will allow me to push the repo to the new remote keeping history?

Flupkear
  • 2,135
  • 7
  • 29
  • 32
  • 1
    You don't need a remote or "another copy of this repo" to do a `git reset --hard`. – vcsjones Jan 25 '12 at 16:05
  • Thanks, didn't know that. I just did it but the problem still exists, the commit that's giving problems it's a very old one. – Flupkear Jan 25 '12 at 16:18
  • two ways: one - look at the file directly (unzip the contents) and see if you can fix it. two - find the commit that references the tree in question and do a hard reset to the parent of that commit. Depending on which commit it is that references the concerning tree, you might lose a lot of data. – Max Leske Jan 25 '12 at 16:19
  • if the commit is so old, you will lose **all** of the history that comes after that commit (it will still be in the repository of course but hard to access). So: do you need the newer commits? – Max Leske Jan 25 '12 at 16:20
  • I would like not to loose newer commits history. The problem seems to be that the file in question is missing, I mean I searched for 9eefe9305253b2c039a54cbc8aa22f7f8e6e8790 in the git folder and it's simply not there. – Flupkear Jan 25 '12 at 16:24
  • Just to make sure: you looked in /.git/9e ? (note that the first two letters denote a subdirectory. The file will have as its name the full hash **minus the two leading characters** (9e)) – Max Leske Jan 25 '12 at 16:27
  • could you run git-fsck on the repo? No point in fixing a tree if there's a lot more damage to the repo... – Max Leske Jan 25 '12 at 16:34
  • yes, the content of .git/objects/9e is 0fb9f0c50080d505d8681310c1bed2a0d46daa 837ff5d831f3c23d925c076c4359b4eafe7caa f8fd9f0f37783827e30b5ba9ff5aae48731a6e 12cac4ebc1d322027b5bb190b11e33d7a931fa b2442e1e5eb5c63d220f77fe69570b23242f80 – Flupkear Jan 25 '12 at 16:38
  • git fsck returns this: broken link from tree 42a55291139e3cfe48fb7444737e17ea5652c536 to blob 9e108293be3997c2d922b4c473a5a28cc737e446 broken link from tree 054b78e2adb08bd87fb9d5afacca95633ee8978e to tree 9eefe9305253b2c039a54cbc8aa22f7f8e6e8790 and it continues with some "dangling commit" – Flupkear Jan 25 '12 at 16:40
  • Doesn't look good. That means that more objects are missing. The answer I just posted below is pretty complicated even if only one object were missing... I'd start by finding a valid commit and then figuring out the changes from there on. If you get a better picture of the changes you might stand a chance of recovering most of it. – Max Leske Jan 25 '12 at 16:45
  • Seems like I should find the commit before and after that, make a patch, apply that to the commit before and pack all that in a file with the missing name. Not sure about an easy way to browse through commits though. – Flupkear Jan 25 '12 at 16:58
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/7042/discussion-between-theseion-and-flupkear) – Max Leske Jan 25 '12 at 17:01

5 Answers5

6

Just Quit the applcation with which you accessing git and restart . Worked for me for xcode-iOS.

Ankish Jain
  • 11,305
  • 5
  • 36
  • 34
4

I ran into this and I really did not want to delete my .git and start over. No other suggestions I found on the internet helped me (including some pretty complicated .git surgery attempts).

The thing that fixed it for me was running:

git fetch --refetch
git gc --aggressive

You can confirm the fix with:

git fsck
hauntsaninja
  • 859
  • 7
  • 11
4

To actually fix the problem and not lose any data (provided that that tree is the only missing object, which I doubt) you could try this:

  1. checkout the parent commit of the commit with the concerning tree
  2. try git cat-file -p with the name of the problematic commit to see what the commit message says (hopefully it will tell you what changed)
  3. now you might be able to determine the changes that were made and from this the directory structure can hopefully be inferred.
  4. if 3 worked, then you can create your tree manually using a text editor and a zlib compressor. The entries in the tee file will be other tree objects or blobs. Hopefully most of the files and folders are shared (have no changes) between the two commits. This will allow you to reuse most of the entries from the tree object of the checked out commit.
Adam Grant
  • 12,477
  • 10
  • 58
  • 65
Max Leske
  • 5,007
  • 6
  • 42
  • 54
  • 1
    The problem is that the file is missing, when I ran *git cat-file -p ...* I get this: error: unable to find 9e108293be3997c2d922b4c473a5a28cc737e446 – Flupkear Jan 25 '12 at 16:44
  • Well, you could look into the commit manually... but you'll most likely have to write a script that will do that for you. Checkout this page for an overview of how the file format looks like: http://book.git-scm.com/1_the_git_object_model.html – Max Leske Jan 25 '12 at 17:01
  • Well, the format of a tree object is pretty straight forward, so if you know what you are doing, you can create a file with the right bytes in it (you'll need all the signatures of the entries of course to do that). I'm not saying that it's a good (or even feasible) solution but it's a possibility to consider if the data is precious. – Max Leske Jul 27 '12 at 11:35
0

I had this problem. Restarting my computer actually fixed it so please try it first before doing anything else. Or maybe I just got lucky but worth a shot!

axsuul
  • 7,370
  • 9
  • 54
  • 71
0

I have my git repo in a directory which is also in the OneDrive folder on my computer. If you use OneDrive on another machine, push from the repo on that computer and then pull/push from your own machine again.

userFog
  • 10,685
  • 1
  • 15
  • 7