Reputation: 2221
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?
Upvotes: 34
Views: 35555
Reputation: 13516
None of the above answers helped me. I got into a bad state when I tried amending a commit while git gc
was running simultaneously (bad idea, apparently :)).
What worked for me was backing up the contents of a file I was editing, running git reset --hard <previous_commit_sha>
, then restoring the contents of a file and making a new commit.
Upvotes: 0
Reputation: 21506
None of these worked for me, since the object itself was gone.
I found a way to go up the tree and delete every object that was referencing this one, and then find the top-most commit and remove said commit from .git/packed-refs
. It could also have been inside .git/refs/heads/your-branch
, but mine were in the packed version.
But there is a much faster way: git fsck --name-objects
, that should tell you the dangling object and its parent (as I'd already found), but also name the object allowing you to more quickly find the broken commit to remove.
This answer is a good way to clear the rest of the backlog afterwards (it'll fully delete it, so make sure you're okay with that): https://stackoverflow.com/a/69639136/179978
Upvotes: 0
Reputation: 999
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
Upvotes: 17
Reputation: 5125
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:
Upvotes: 4
Reputation: 11499
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.
Upvotes: 0
Reputation: 11361
Just Quit the applcation with which you accessing git and restart . Worked for me for xcode-iOS.
Upvotes: 7
Reputation: 7480
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!
Upvotes: 0