Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

version control - How to fix a bad git tree object

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...