恢复在分离的HEAD中推送的更改

时间:2017-07-08 17:11:22

标签: git

我有我的git 2分支,master和SSL 虽然我以为我在主分支上,但实际上我是超脱的。我将更改推送到HEAD,然后结帐到SSL分支并合并它 当我这样做时,我发现对主人的改变没有出现在任何一个分支上,我看不到它们 有没有办法恢复丢失的提交?

正在运行git reflog -n 20

 e4a206b HEAD@{0}: checkout: moving from SSL to master
94e0f8d HEAD@{1}: checkout: moving from master to SSL
e4a206b HEAD@{2}: checkout: moving from SSL to master
94e0f8d HEAD@{3}: reset: moving to 94e0f8d
18aedb9 HEAD@{4}: checkout: moving from master to SSL
e4a206b HEAD@{5}: checkout: moving from e4a206b20456d004b5ad19bb859e15f481df9b90 to master
e4a206b HEAD@{6}: checkout: moving from SSL to master^0
18aedb9 HEAD@{7}: checkout: moving from master to SSL
e4a206b HEAD@{8}: checkout: moving from e4a206b20456d004b5ad19bb859e15f481df9b90 to master
e4a206b HEAD@{9}: checkout: moving from master to master^0
e4a206b HEAD@{10}: checkout: moving from d8b6feee2ae2595872d62ca2b25c01263b3bf74b to master
d8b6fee HEAD@{11}: merge SSL: Merge made by the 'recursive' strategy.
94e0f8d HEAD@{12}: commit: Support for os and badge count for ios
e4a206b HEAD@{13}: checkout: moving from 18aedb908898083d8b9d6941ec59f981950a3846 to master^0
18aedb9 HEAD@{14}: checkout: moving from bc071caacff35fca304aae97804fd9070d92913f to SSL^0
bc071ca HEAD@{15}: commit: Added support for sell option
e4a206b HEAD@{16}: checkout: moving from 18aedb908898083d8b9d6941ec59f981950a3846 to master^0
18aedb9 HEAD@{17}: checkout: moving from e4a206b20456d004b5ad19bb859e15f481df9b90 to SSL^0
e4a206b HEAD@{18}: checkout: moving from SSL to master^0
18aedb9 HEAD@{19}: commit: SSL

我已经对我想要的提交进行了硬重置,它仍然缺少一个文件(我真的不知道如何)。

1 个答案:

答案 0 :(得分:1)

基于git reflog,您似乎在git reset处运行了94e0f8d HEAD@{3}

您应该可以通过在重置前检查提交来恢复任何已提交的工作:git checkout HEAD@{4}

最后一个想法:当你收到一个"分离的HEAD"通知,运行git status获取一些有用的指导:

  

你处于分离头部'州。你可以四处看看,制作   实验更改并提交它们,您可以放弃任何提交   你在这种状态下通过表演而不影响任何分支   另一个结账。

     

如果您想创建一个新分支来保留您创建的提交,那么   可以通过再次使用-b和checkout命令来实现(现在或以后)。   例如:

     

git checkout -b new-branch-name

     

HEAD现在是81f96ab ...有些提交msg