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

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

    The following method may work:

    git rebase HEAD master
    git checkout master
    

    This will rebase your current HEAD changes on top of the master. Then you can switch the branch.


    Alternative way is to checkout the branch first:

    git checkout master
    

    Then Git should display SHA1 of your detached commits, then you can cherry pick them, e.g.

    git cherry-pick YOURSHA1
    

    Or you can also merge the latest one:

    git merge YOURSHA1
    

    To see all of your commits from different branches (to make sure you've them), run: git reflog.

提交回复
热议问题