git 警告:您将留下 1 个提交,未连接到您的任何分支

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14365736/
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 15:17:07  来源:igfitidea点击:

Warning: you are leaving 1 commit behind, not connected to any of your branches

gitversion-controlbranching-and-merging

提问by Naftuli Kay

EGit strikes again. I made the mistake of trying to switch to a different branch in EGit and it somehow messed up and checked out no branch. I then made a commit to this non-branch, and then when I realized I wasn't tracking the right branch, I ran the following:

EGit 再次出击。我犯了一个错误,试图在 EGit 中切换到不同的分支,但不知何故搞砸了,没有检查出任何分支。然后我对这个非分支进行了提交,然后当我意识到我没有跟踪正确的分支时,我运行了以下命令:

$ git checkout issue2
Warning: you are leaving 1 commit behind, not connected to any of your branches:

    bada553d My commit message

If you want to keep them by creating a new branch, this may be a good time to do so with:

    git branch new_branch_name ....

Branch issue2 set up to track remote branch issue2 from origin.
Switched to a new branch issue2. 

Now that I've botched things, how do I associate that commit with my current branch? I'm not interested in creating a brand new branch, I just want to pull that commit into my branch, issue2.

既然我已经搞砸了,我如何将该提交与我当前的分支相关联?我对创建一个全新的分支不感兴趣,我只想将该提交拉入我的分支,issue2.

回答by Adam Dymitruk

you can git cherry-pick bada553dif it's just the one commit.

git cherry-pick bada553d如果只是一次提交,你可以。

You can also reference anywhere you've been by using the reflog:

您还可以使用 reflog 引用您去过的任何地方:

git reflog

then use one of those commits:

然后使用这些提交之一:

git checkout -b temp HEAD@{3}

to checkout and make a branch temp from where your current commit was 3 "times" ago. It's a bread crumb of where you used to be.

结帐并从您当前提交 3“次”前的位置创建一个分支临时。这是你以前所在的面包屑。