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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 09:58:43  来源:igfitidea点击:

gitx How do I get my 'Detached HEAD' commits back into master

gitversion-control

提问by Travis

Using Git X and must have fumbled royally on something. Looks like a few days ago I created a branch called detached HEADand have been committing to it. My normal process is to commit to masterand 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 HEADbranch 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 masterwas the last thing you did, then the reflogentry HEAD@{1}will contain your commits (otherwise use git reflogor git log -pto find them). Use git merge HEAD@{1}to fast forward them into master.

如果这checkout master是您做的最后一件事,那么reflog条目HEAD@{1}将包含您的提交(否则使用git refloggit log -p查找它们)。用于git merge HEAD@{1}将它们快进到 master。

EDIT:

编辑:

As noted in the comments, Git Ready has a great articleon this.

正如评论中所指出的,Git Ready 有一篇很棒的文章

git reflogand git reflog --allwill give you the commit hashes of the mis-placed commits.

git reflog并且git reflog --all会给你提交错误放置提交的哈希值。

Git Ready: Reflog, Your Safety Net

Git 就绪:Reflog,您的安全网

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.

将它合并回您的本地主服务器。