How can I recover my Git repository for a “missing tree” error?

╄→尐↘猪︶ㄣ 提交于 2019-11-28 05:49:33
Filip

Use git push --no-thin instead of git push.

From Git docs:

A thin transfer significantly reduces the amount of sent data when the sender and receiver share many of the same objects in common. The default is --thin.

I am getting this same error on my tortiuse git. I finally get the root cause of this error.

The steps which causes this error;

  • Create a new branch on head.
  • Do some modifications on new branchs
  • Somebody also make modifications on head branch
  • Try to push your branch

This error will occur if a local branch is created and not pushed until some modifications ara made in head branch. This is a normal thing, since remote head branch do not know anything about your local branch until a push action.

To solve this error, switch the head branch get a full pull action. Then switch your branch and try a push.

Jeff Ferland

Back it up... back it up right this second before you try anything.

Now, that sounds unfortunate. It's also a shame that it doesn't sound like you have a regular backup to go to. There is good news to be had, though: I bet your developers have this file, though it may be in a pack file. Try the following in somebody else's .git directory. Note that git uses the first two characters of the hash for the directory name.

find . -name d62f0ed4385e3f68f226ac133fa9932a9c65c9

If that shows up, copy that file to the same relative path on your server, and life should move on nicely. If not, then try this:

find . -name \*.idx -exec cat {} \; | git show-index | grep 14d62f0ed4385e3f68f226ac133fa9932a9c65c9

That won't show you which pack file it is (you can quickly script this or do it manually), but it will tell you its there. Find the right pack file and expand it...

git unpack-objects $FILE

From there, copy the file to the same relative path on your server. If that doesn't solve it, further work is needed. Swapping a developer's up-to-date-enough repository might fix things. You may also want to explore https://git.wiki.kernel.org/index.php/GitFaq#How_to_fix_a_broken_repository.3F, or post update comments and wait for me to get back around to this.

When we get this, I can almost always fix it with a git gc:

git gc --aggressive --prune=now

back up your git repo first!

Try a git pull --rebase.

I saved the diff (git show > ~/mychanges.txt, took out the commit msg at the top of the file). The checked out a new branch (git checkout -b newbranch) applied the changes (git apply ~/mychanges.txt), and then did a git pull --rebase. Then everything worked.

If not on master branch, you can simply delete the remote branch by:

git push --delete origin <branch_name>

And then push your branch back to the remote:

git push -u origin <branch_name>

I had the same problem. To solve this I used git fetch then I pushed again and it worked just fine.

Try upgrading your version of git, we saw issues with 1.9.0

Shubham Vatsal

This generally happens when time of commit and push is different and which ultimately creates a mismatch between both the trees. Given a remote branch upstream and local branch foo

Firstly throw away all the uncommitted changes using

git reset --hard foo

Then track the remote branch using

git branch --set-upstream-to=upstream/foo

And finally

git pull

Technically this answer's a little late, but what worked for me was to create a patch for the changeset I was trying to push, recloned the repository to another disk location, Applied the patch, recommitted, and pushed.

Quick solution is Fetch -> Rebase-> Commit and then Push.

I deleted my master branch and created once again. Its working . git branch -D master, git checkout master Luckily it working

In my case it turned out I forgot to git fetch before git rebase -i origin/master. Thus when I tried to push to gerrit, I got the above error.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!