git gitx 如何让我的“分离头”提交回主
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4845505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
gitx How do I get my 'Detached HEAD' commits back into master
提问by Travis
Using Git X and must have fumbled royally on something. Looks like a few days ago I created a branch called detached HEAD
and have been committing to it. My normal process is to commit to master
and then push that to origin
. But I can't push detached HEAD
.
使用 Git X 并且一定在某些事情上笨手笨脚。看起来几天前我创建了一个名为的分支detached HEAD
并一直致力于它。我的正常过程是提交master
,然后将其推送到origin
. 但我不能推detached HEAD
。
My next stop screwed me. I selected git checkout master
- and my detached HEAD
branch disappeared. Going back to my project all of my changes in the past few days have been wiped.
我的下一站搞砸了我。我选择了git checkout master
- 我的detached HEAD
分支消失了。回到我的项目,这几天我所有的变化都被抹去了。
Is there anyway I can get those changes back?
无论如何我可以恢复这些更改吗?
回答by Josh Lee
If checkout master
was the last thing you did, then the reflogentry HEAD@{1}
will contain your commits (otherwise use git reflog
or git log -p
to find them). Use git merge HEAD@{1}
to fast forward them into master.
如果这checkout master
是您做的最后一件事,那么reflog条目HEAD@{1}
将包含您的提交(否则使用git reflog
或git log -p
查找它们)。用于git merge HEAD@{1}
将它们快进到 master。
EDIT:
编辑:
As noted in the comments, Git Ready has a great articleon this.
正如评论中所指出的,Git Ready 有一篇很棒的文章。
git reflog
and git reflog --all
will give you the commit hashes of the mis-placed commits.
git reflog
并且git reflog --all
会给你提交错误放置提交的哈希值。
Source: http://gitready.com/intermediate/2009/02/09/reflog-your-safety-net.html
来源:http: //gitready.com/intermediate/2009/02/09/reflog-your-safety-net.html
回答by richo
If your detached HEAD is a fast forward of master and you just want the commits upstream, you can
如果您分离的 HEAD 是 master 的快进并且您只想要上游提交,则可以
git push origin HEAD:master
to push directly, or
直接推动,或
git checkout master && git merge [ref of HEAD]
will merge it back into your local master.
将它合并回您的本地主服务器。