Fix a Git detached head?

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

    Detached head means you have not checked out your branch properly or you have just checked out a single commit.

    If you encounter such an issue then first stash your local changes so that you won't lose your changes.

    After that... checkout your desired branch using the command:

    Let's say you want branch MyOriginalBranch:

    git checkout -b someName origin/MyOriginalBranch

提交回复
热议问题