如何恢复我的 Git 存储库中的“丢失的树”?错误?
我们使用 Gerrit 作为我们的 Git 存储库。在一个已经活跃了几个月的项目上,我们突然无法推动任何更改。当我们执行 git push 时,我们会看到以下错误:
error: unpack failed: error Missing tree 14d62f0ed4385e3f68f226ac133fa9932a9c65c9
执行 git fsck --full 会产生:
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我们的开发人员在尝试推送时遇到了同样的错误。到目前为止,我们已经尝试重新初始化 gerrit 存储库(git init --bare ...)并推送它。我们还尝试使用单独的存储库创建一个新的 gerrit 项目。最后,我们不断遇到同样的错误。
有谁知道原因是什么,或者如何恢复?
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 Missing 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(14)
使用 git push --no-thin 代替 git push 。
来自 Git 文档:
Use
git push --no-thin
instead ofgit push
.From Git docs:
我的乌龟 git 上也遇到同样的错误。我终于找到了这个错误的根本原因。
导致此错误的步骤;
如果创建了本地分支并且直到在 head 分支中进行了一些修改才推送,则会出现此错误。这是正常的事情,因为远程头分支在推送操作之前不知道有关本地分支的任何信息。
要解决此错误,请切换头部分支以获得完整的拉动操作。然后切换你的分支并尝试推送。
I am getting this same error on my tortoise git. I finally get the root cause of this error.
The steps which causes this error;
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.
我也有同样的问题。为了解决这个问题,我使用了 git fetch 然后再次推送,效果很好。
I had the same problem. To solve this I used git fetch then I pushed again and it worked just fine.
备份...在尝试任何操作之前立即备份。
现在,这听起来很不幸。令人遗憾的是,听起来您没有定期备份可供使用。不过,有个好消息:我敢打赌您的开发人员有这个文件,尽管它可能位于包文件中。在其他人的 .git 目录中尝试以下操作。 请注意,git 使用哈希的前两个字符作为目录名称。
如果出现这种情况,请将该文件复制到服务器上的相同相对路径,然后生活应该会顺利进行。如果没有,请尝试以下操作:
它不会显示它是哪个包文件(您可以快速编写脚本或手动执行此操作),但它会告诉您它在那里。找到正确的包文件并将其展开...
从那里,将文件复制到服务器上的相同相对路径。如果这不能解决问题,则需要进一步的工作。更换开发人员的足够最新的存储库可能会解决问题。您可能还想探索 https://git.wiki.kernel.org /index.php/GitFaq#How_to_fix_a_broken_repository.3F,或发布更新评论并等待我回来解决此问题。
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.
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:
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...
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.
当我们得到这个时,我几乎总是可以用 git gc 修复它:
首先备份你的 git 存储库!
When we get this, I can almost always fix it with a git gc:
back up your git repo first!
尝试 git pull --rebase 。
我保存了差异(
git show > ~/mychanges.txt
,取出文件顶部的提交消息)。签出一个新分支 (git checkout -b newbranch
) 应用更改 (git apply ~/mychanges.txt
),然后执行git pull - -rebase
。然后一切都正常了。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 agit pull --rebase
. Then everything worked.如果不在主分支上,您可以简单地通过以下方式删除远程分支:
然后将分支推回远程:
If not on master branch, you can simply delete the remote branch by:
And then push your branch back to the remote:
先尝试做一下
然后做
遇到同样的问题。上述解决方案对我有用。
Try to do first
then do
Got same problem. above solution worked for me.
当提交和推送时间不同时,通常会发生这种情况,并最终导致两棵树之间不匹配。给定一个远程分支 upstream 和本地分支 foo
首先使用丢弃所有未提交的更改
然后使用跟踪远程分支
最后
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
Then track the remote branch using
And finally
奇怪的是,
--no-thin
论点对我不起作用。有效的是 git pull (所以可能是 git fetch 。Weird, the
--no-thin
argument didn't work for me. What worked was agit pull
(so probablygit 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.
我删除了主分支并再次创建。它的工作。
git分支-D主控,
git 结账大师
幸运的是它有效
I deleted my master branch and created once again. Its working .
git branch -D master,
git checkout master
Luckily it working
就我而言,事实证明我在 git rebase -i origin/master 之前忘记了 git fetch 。因此,当我尝试推送到 gerrit 时,出现了上述错误。
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.