質問

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 git@github.com:xxx/xxx.git
役に立ちましたか?

解決

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.).

他のヒント

That is normal behaviour. The reflog keeps track of where head used to be and where branches used to be. So doing

git checkout master
git checkout experiment
git checkout master
git checkout experiment
git checkout master
git checkout experiment

will end up with

2aad8cb HEAD@{0}: checkout: moving from master to experiment
d8cbf4b HEAD@{1}: checkout: moving from experiment to master
2aad8cb HEAD@{2}: checkout: moving from master to experiment
d8cbf4b HEAD@{3}: checkout: moving from experiment to master
2aad8cb HEAD@{4}: checkout: moving from master to experiment
d8cbf4b HEAD@{5}: checkout: moving from experiment to master

in the reflog. You can see the values repeating.

Here I've used git checkout - a few times to switch between checking out a SHA-1 (detached head) and master:

5016d9e (HEAD, origin/master, master) HEAD@{0}: checkout: moving from 5016d9e82379923c21268e73e4dad3122a5639ac to master
5016d9e (HEAD, origin/master, master) HEAD@{1}: checkout: moving from master to 5016d9e82379923c21268e73e4dad3122a5639ac
5016d9e (HEAD, origin/master, master) HEAD@{2}: checkout: moving from 5016d9e82379923c21268e73e4dad3122a5639ac to master
5016d9e (HEAD, origin/master, master) HEAD@{3}: checkout: moving from master to 5016d9e82379923c21268e73e4dad3122a5639ac
5016d9e (HEAD, origin/master, master) HEAD@{4}: checkout: moving from 5016d9e82379923c21268e73e4dad3122a5639ac to master

You can see that the same SHA1 entry repeats.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top