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

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

    git checkout master
    

    That's result something like this:

    Warning: you are leaving 2 commits behind, not connected to
    any of your branches:
    
    1e7822f readme
    0116b5b returned to clean django
    
    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 1e7822f25e376d6a1182bb86a0adf3a774920e1e
    

    So, let's do it:

    git merge 1e7822f25e376d6a1182bb86a0adf3a774920e1e
    

提交回复
热议问题