Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typo3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 警告:您将留下1个提交,未连接到您的任何分支_Git_Version Control_Branching And Merging - Fatal编程技术网

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

Git 警告:您将留下1个提交,未连接到您的任何分支,git,version-control,branching-and-merging,Git,Version Control,Branching And Merging,艾吉特又来了。我犯了一个错误,试图切换到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 t

艾吉特又来了。我犯了一个错误,试图切换到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. 

既然我把事情搞砸了,我该如何将提交与我当前的分支相关联?我对创建一个全新的分支不感兴趣,我只想把这个承诺拉到我的分支中,
issue2

如果只是一个提交,您可以
git cherry pick bada553d

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

git reflog
然后使用其中一个提交:

git checkout -b temp HEAD@{3}

签出并从当前提交3次之前的位置创建分支临时。这是你过去的面包屑。

太棒了,成功了。非常感谢!你不知道你刚刚救了我什么。谢谢,Adam。如何像这样删除不需要的提交?如果你不给它一个名称,比如分支或标记,它最终会被git的垃圾收集器删除。可能是