How to understand HEAD and branch? in git

HEAD and branch are two special references in git, both pointing to commit. And in general, HEAD points to branch and then points to commit, but when HEAD is free, it no longer points to branch but directly to commit, so it seems inaccurate to say that HEAD is a cursor pointing to the active branch, but to the current commit.

the branch, is essentially a reference to commit, where the commit is a single commit,. When a new commit submission is made, the branch moves to the new commit. However, when we submit a lot of commit, on the branch and then merge all the commits of the branch, can we understand the branch as a commit string? it represents that all the submitted commit, are essentially merged with the commit string when merging, which seems reasonable, but it is not consistent with the definition of "the essence of branch is a reference to commit". This sentence in my understanding is that branch only refers to a single commit.

also ask all the gods to help me understand, thank you!

Git
Apr.27,2021

The understanding that

branch only points to a single commit is correct.

the reason why you understand branch as a commit string is that git stores these commit as a tree structure that describes their sequential relationships

explain it in code:

  git  

Menu