Git: “Not currently on any branch.” Is there an easy way to get back on a branch, while keeping the changes?

后端 未结 9 634
梦谈多话
梦谈多话 2020-12-12 08:26

So I\'ve done some work in the repository and when I\'m about to commit I realize that I\'m not currently on any branch.

This happens a lot when working with submodu

9条回答
  •  我在风中等你
    2020-12-12 09:11

    I know I told babay in 2012 that I thought it was unlikely that someone wouldn't realize that they weren't on a branch and commit. This just happened to me, so I guess I have to admit that I was wrong, but considering that it took until 2016 for this to happen to me, you could argue that it is in fact unlikely.

    Anyway, creating a new branch is overkill in my opinion. All you have to do is:

    git checkout some-branch
    git merge commit-sha
    

    If you didn't copy the commit-sha before checking out the other branch, you can easily find it by running:

    git reflog
    

提交回复
热议问题