从远程git存储库中恢复未提交的提交 [英] Recover unreferenced commits from remote git repository
问题描述
不幸的是,有人做了 push -f
,这样任何远程分支都不会引用这些提交。
更糟糕的是,我没有在本地克隆中提交这些提交。
我的目标基本上是恢复那些提交。这些是我尝试过的一些事情:
-
git checkout -b恢复< commit_id>
:fatal:引用不是树 -
git push origin< commit_id>:recovery
错误:refs / heads / recovery没有指向有效的对象!错误:
无法推送到不合格目标:恢复目标
refspec既不匹配远程的现有参考,也不以
refs /开头,我们无法根据来源引用
存储库位于bitbucket上,并且提交可以从Web界面访问,所以它没有被垃圾回收。
问题是您的本地存储库没有该提交ID。 b
git checkout -b恢复< commit_id>
git push origin< commit_id>:recovery
这两个命令都因此失败,如果我使用本地不存在的提交ID,我会得到与GitHub回购完全相同的消息。
我认为答案只是简单地提取丢失的提交在本地,以下列方式之一:
git fetch origin#1
git fetch origin SHA1#2
git fetch origin SHA1:refs / remotes / origin / recovery#3
不幸的是,这些工作都没有成功。根据这个答案。截至目前,它不再有效。
有一个帮助页面在GitHub上,但没有答案,你可以使用:它基本上说,如果你有你可以在本地创建一个分支并推送它。是的,但是如果你本地没有提交,那么是什么?它不会回答。
我可以考虑两种选择:
- 找到有这个提交的队友。用
git log SHA1
检查很容易。如果任何人拥有它,他们可以使用git分支恢复SHA1
从它创建一个分支,然后推送它。 联系bitbucket支持。因为他们有提交,所以他们应该能够为你创建一个恢复
分支。
Here's the situation : some commits have been done in a remote repository.
Unfortunately, someone did push -f
such that no remote branch references these commits anymore.
To make matters worse, I don't have those commits in my local clone.
My goal is basically to recover those commits. These are some of the things I tried :
git checkout -b recovery <commit_id>
: fatal: reference is not a treegit push origin <commit_id>:recovery
error: refs/heads/recovery does not point to a valid object! error: unable to push to unqualified destination: recovery The destination refspec neither matches an existing ref on the remote nor begins with refs/, and we are unable to guess a prefix based on the source ref.
The problem is that your local repository doesn't have that commit id.
git checkout -b recovery <commit_id>
git push origin <commit_id>:recovery
Both of these commands fail for that reason, I get the exact same messages with a GitHub repo if I use a commit id that doesn't exist locally.
I thought the answer will be simply fetching the lost commits locally, in one of these ways:
git fetch origin #1
git fetch origin SHA1 #2
git fetch origin SHA1:refs/remotes/origin/recovery #3
Unfortunately none of these work. It seems #2 used to work as of Git v1.4 according to this answer. As of now, it doesn't work anymore.
There is a help page for this on GitHub, but with no answer that you can use: it basically says that if you have the commit locally you can create a branch from it and push it. Yeah, but if you don't have the commit locally then what? It doesn't answer that.
I can think of two options:
- Find a teammate who has this commit. It's easy to check with
git log SHA1
. If anybody has it, they can create a branch from it withgit branch recovery SHA1
and then push it. - Contact bitbucket support. Since they have the commit, somewhere, they should be able to create a
recovery
branch for you.
这篇关于从远程git存储库中恢复未提交的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!