Search code examples
gitversion-controlgit-reflog

why new head and old head have the same sha id using git reflog?


i think these should be two different HEADS, so why they corresponds to the same sha value, that is 2aad8cb ...

git reflog
2aad8cb HEAD@{0}: checkout: moving from master to xxx_master   
2aad8cb HEAD@{1}: clone: from [email protected]:xxx/xxx.git

Solution

  • When you first create a new branch via git branch newbranch or git checkout -b newbranch master, newbranch will point to exactly the same commit as the branch point (whatever HEAD was in the first example, or master in the second). So it would be normal to see, for example, master and newbranch both having the same SHA. When you create a new commit on either branch, then that branch will point to the new commit, which will have the previous value as its parent (over-simplifying to avoid discussing merges, etc.).