Git HEAD detached from XXX

1 Overview

HEAD in Git can be understood as a pointer, which can point to a branch or a snapshot. We can enter cat .git/HEAD on the command line to see where the current HEAD points. Generally, it points to the latest commit of the branch where the current working directory is located.

cat .git/HEAD
ref: refs/heads/<branch name>  // 正常
cad0be9ceb89f474c39360c4de337d4a8194cab0 // 游离状态

Use git checkout to move the HEAD pointer. The moved object can be a branch pointer or a snapshot.

"detached HEAD" state - the HEAD head pointer points to a specific commit ID, not a branch. At this time, HEAD is in the detached state (free state)

2.Solution

1. Check the current branch status.
Use the status command to check the git status: it is found that HEAD detached points to 57f51ee, which is the last commit.

git branch
* (HEAD detached at 57f51ee)
master

2. Create a new temporary temp branch and put the currently submitted [modified] code on this branch.

git branch temp
git checkout temp

3. Change back to the branch you want to return to, here is master

git checkout master

4. Then merge the temporary branch just created

git merge temp

5. Check if there is any conflict. If not, submit it to the remote end.

git push origin master

6. Delete the temporary branch

git branch -d temp

Guess you like

Origin blog.csdn.net/qq_44804542/article/details/117923914