Git's detached HEAD

Source: Internet
Author: User

Today, I encountered the same problem with CSDN, that is, using git-branch-a to find yourself at a zero-point branch. This blog post is very good, reproduced record.

Reprint: http://blog.csdn.net/lili625/article/details/46583217

+ Git fetch--allfetching originaddress IP address maps to git address, but Thisdoes not map back to the address-possible break-in attempt!+git checkout masterprevious HEAD position was8928318... add test fileswitched to branch' Master 'Your Branch and' Origin/master 'Have Diverged,and1487 and 409different commits each, respectively. ( use"Git Pull"To merge the remote branch into yours)+git pulladdress IP address maps to git address, but Thisdoes not map back to the address-possible break-in attempt!Auto-merging upgrade-framework/conf/shell.xmlconflict (Add/add): Merge conflict in upgrade-framework/conf/Shell.xmlauto-merging upgrade-framework/conf/replace.xmlconflict (Add/add): Merge conflict in upgrade-framework/conf/replace.xml ...

Which "Your branch and ' Origin/master ' have diverged" this sentence aroused my attention, translated into Chinese is "your branch and ' Origin/master ' branch has a disagreement", because the previous command is Git Checkout master, so the current branch is master, which ultimately means that the master branch and the Origin/master branch are divided. We all know that the default branch of the Git repository is that Master,origin/master is the branch that corresponds to the far end, why is there a disagreement? Let's take a concrete look.
Run git status on the local master branch first to check the status and find nothing to commit,working directory clean. So run git checkout origin/master switch to the Origin/master branch to see what has been found no, sure enough:

After switching the branch information I am in the ' detached HEAD ' state. Detached is the meaning of free, head is a special term in git.

You can think of HEAD (uppercase) as "current Branch" (the next branch). When you switch branches with git checkout, the HEAD revision points back to the new branch. Sometimes head points to a revision with no branch name, which is called "detached head". The head (lowercase) is a reference to the Commit object, each head has a name (branch name or tag name, etc.), but by default, each repository called Master has a head, A repository can contain any number of head. At any time, as long as the head is chosen to be "current head", the head is head and always capitalized. --Excerpt from Segmentfalt

The above paragraph is from the network answer, the definition of head and also explains what is called ' detached head ', which is now head pointing to a revision without a branch name, "Free" outside of all known branches. Here, I guess the error of the console report should be related to the free head. Naturally, if you want to solve the error of git docking The Jenkins times, you need to solve the ' detached HEAD ' problem.
So I tried commit:

As in the master branch, there is no need to commit, but the Scarlet Letter identifies head detached at Origin/master and once again verifies that the head is free from the Origin/master branch.
To view the most recent changes to a branch:

Here we see that the latest commit ID of the three branches with the unnamed branch of the free head is a239482. Looking back at the first picture, there is a word "HEAD is now at C90B1CA ... Add Test.txt file ". Test.txt file is the file I made clear about the branch status for the test, then a modification was made, and the new one was definitely before the change. Do not know what causes the head still stuck in the new Test.txt file here does not continue to go forward.

Search the Internet a lot of information, and finally found that the solution to this problem is not complicated. Simply put, the problem with the free head is that it doesn't have a specific branch name, so let's give it a name: Git branch temp C90B1CA (name the commit with head pointing to Branch temp), and then switch to Branch master, and execute the merge command ( Git merge temp) and push to the far end. After doing this series of operations to see the latest changes in the branch again, found that the free branch is missing, instead of the temp branch.

Not surprisingly, the problem with git docking Jenkins also disappeared.

Git's detached HEAD

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.