Home > Article > Development Tools > What is the git detached head pointer?
The git detached head pointer is a state where the HEAD pointer no longer points to the branch, but directly points to a commit; generally the HEAD pointer points to the branch, and the branch points to the commit, and the detached head pointer refers to The changes are not based on a certain branch. When we switch branches, the changes are likely to be lost. In this case, we need to create a new branch and bind the changes to the branch.
The operating environment of this article: Windows 10 system, Git version 2.30.0, Dell G3 computer.
When Git is used, there is a state called the detached head pointer state, also called detached HEAD.
We can learn from previous updates that in Git the HEAD pointer points to the branch, and the branch points to the commit. The so-called detached head pointer state means that the HEAD pointer no longer points to the branch, but directly points to a commit.
Usually, we work on a certain branch, such as the master branch. At this time, the master pointer and the HEAD pointer are moving forward together. Every time a commit is made, these two pointers will move forward one step together. However, under certain circumstances (such as checking out a specific commit), the "binding" state of the master pointer and the HEAD pointer is broken and becomes the detacged HEAD state.
The detached head pointer refers to the change that is not based on a certain branch. When we switch branches, the change is likely to be lost. At this time we need to create a new branch and bind the change to the branch.
1. As shown in the picture below, I am currently in a normal state
#2. At this time, I switched to a commit and the detached head pointer state appeared.
3. Modify the file content in the detached head pointer state and submit
Recommended study: " Git tutorial》
The above is the detailed content of What is the git detached head pointer?. For more information, please follow other related articles on the PHP Chinese website!