“git checkout ” is changing branch to “no branch”

后端 未结 5 546
没有蜡笔的小新
没有蜡笔的小新 2021-01-31 08:30

I am working on a branch in git. When I do

git checkout 

(commit id obtained from git log ), it is getting commit

5条回答
  •  一个人的身影
    2021-01-31 09:08

    If you checkout a commit sha directly, it puts you into a "detached head" state, which basically just means that the current sha that your working copy has checked out, doesn't have a branch pointing at it.

    If you haven't made any commits yet, you can leave detached head state by simply checking out whichever branch you were on before checking out the commit sha:

    git checkout 
    

    If you did make commits while you were in the detached head state, you can save your work by simply attaching a branch before or while you leave detached head state:

    # Checkout a new branch at current detached head state:
    git checkout -b newBranch
    

    You can read more about detached head state at the official Linux Kernel Git docs for checkout.

提交回复
热议问题