我最初有一个分支,但我不小心用git分支-M命令覆盖了另一个分支。
有没有办法恢复被覆盖的分支(散列)?
Reflog没有显示任何以前的提交散列,并且我在任何地方都找不到原始分支的提交散列。
发布于 2016-07-19 00:02:08
我做了个测试。
$ git branch
* master
$ git reflog master
63fa031 master@{0}: clone: from git://192.168.70.128/
$ git branch -M master nice
$ git branch
* nice
$ git reflog master
fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
$ git reflog nice
63fa031 nice@{0}: Branch: renamed refs/heads/master to refs/heads/nice
63fa031 nice@{1}: clone: from git://192.168.70.128/因此,git reflog <newbranch>可以显示重命名历史记录。
发布于 2016-07-19 00:53:24
不幸的是,重命名分支似乎也会重命名(在您的情况下,覆盖)其reflog,因此您不能再访问被覆盖的分支的reflog。
但是,提交散列仍然可以在git reflog中提及,因为它记录分支签出。如果reflog中没有提到提交(或者您不确定是否提到了),请尝试git fsck --no-reflogs,它将列出(以及其他内容)所有悬空提交,其中一个应该是被覆盖分支的头部。
https://stackoverflow.com/questions/38441082
复制相似问题