Fix a Git detached head?

前端 未结 23 1759
臣服心动
臣服心动 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:21

    Detached head means:

    1. You are no longer on a branch,
    2. You have checked out a single commit in the history

    If you have no changes: you can switch to master by applying the following command

      git checkout master
    

    If you have changes that you want to keep:

    In case of a detached HEAD, commits work like normal, except no named branch gets updated. To get master branch updated with your committed changes, make a temporary branch where you are (this way the temporary branch will have all the committed changes you have made in the detached HEAD), then switch to the master branch and merge the temporary branch with the master.

    git branch  temp
    git checkout master
    git merge temp
    

提交回复
热议问题