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

后端 未结 9 635
梦谈多话
梦谈多话 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:13

    One way to end up in this situation is after doing a rebase from a remote branch. In this case, the new commits are pointed to by HEAD but master does not point to them -- it's pointing to wherever it was before you rebased the other branch.

    You can make this commit your new master by doing:

    git branch -f master HEAD
    git checkout master
    

    This forcibly updates master to point to HEAD (without putting you on master) then switches to master.

提交回复
热议问题