git - 警告 : you are leaving 1 commit behind, 未连接到您的任何分支

标签 git version-control branching-and-merging

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. 

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

最佳答案

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

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

git reflog

然后使用其中一个提交:

git checkout -b temp HEAD@{3}

从当前提交 3“次”之前的位置 checkout 并创建一个临时分支。它是您过去所在位置的面包屑。

关于git - 警告 : you are leaving 1 commit behind, 未连接到您的任何分支,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14365736/

相关文章:

branching-and-merging - 在TFS 2012中重命名分支的后果是什么?

git - 将现有的 git 存储库转换为 git-lfs

git - 如何解决git中文件重命名文件夹的冲突?

git - 使用 Git 存储库时遇到问题

git - git 的奇怪行为

git - 你在现实世界中如何使用 GIT?

java - 编译文件时是否可以选择版本号?

Git hotfix 分支 merge

git 子命令 VS git --option

来自本地文件夹的 git 子模块