Fix a Git detached head?

前端 未结 23 1380
臣服心动
臣服心动 2020-11-22 05:42

I was doing some work in my repository and noticed a file had local changes. I didn\'t want them anymore so I deleted the file, thinking I can just checkout a fresh copy. I

23条回答
  •  [愿得一人]
    2020-11-22 06:25

    If you made changes and then realized that you are on a detached head, you can do: stash -> checkout master -> stash pop:

    git stash
    git checkout master   # Fix the detached head state
    git stash pop         # Or for extra safety use 'stash apply' then later 
                          #   after fixing everything do 'stash drop'
    

    You will have your uncommited changes and normal "attached" HEAD, like nothing happened.

提交回复
热议问题