开发者

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

We are using Gerrit for our Git repository. On a project that has been active for several months, we are suddenly unable to push any changes. When we execute git push we see the following error:

error: unpack failed: error Miss开发者_运维技巧ing tree 14d62f0ed4385e3f68f226ac133fa9932a9c65c9

Executing git fsck --full yields:

dangling tree 2701c92fb6eab1826482f6bcc9598413e651a92a  
dangling blob c505b3b12cfacd1e26dec8dc559820a30fc20c27  
dangling blob 8907f94b5b4ec881e1b86d50681795e368c167ff  
dangling blob 4938d9fc34c6e2f92c68872bfec6e070b2b3a9c2  
dangling blob 8a5c8b8d35484ea1470e2d8e6c482fcb97b23d0f  
dangling commit 3072d3314e20bf6c6998e1c02986d83019d3e1df  
dangling tree 5377d7f7111d340854c3ee0946667c202227e603  
dangling tree c3783e9ab540457924ceb9f9fb5ea1c2b97472b1  
dangling blob 8b92d1765038e4ec5e721f98a2aabb305a7f9819  
dangling tree 38a03153f0f18ca15846e9bd4983a86800a43a94  
dangling commit 8db2d6ae5364174bebe13720a359ddb2e62d4c9d  

All of our developers are experiencing the same error when they try to push. So far, we've tried re-initializing the gerrit repo (git init --bare ...) and pushing up to it. We've also tried creating a new gerrit project with a separate repo. In the end, we keep getting the same error.

Does anyone have any insight on what the cause would be, or how to recover?


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 are 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.


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


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>


Try to do first

git gc

then do

git push

Got same problem. above solution worked for me.


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


Weird, the --no-thin argument didn't work for me. What worked was a git pull (so probably git fetch.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜