Two branches that compare with git diff but have different hashes

Usually, when two branches coincide in the same source code, they will hash and be displayed together. But I was in an interesting state (described in the title).

This is how I got there. I had an old branch from last week, and I combined a lot of changes from the master into it. At the moment it was fast forward and, besides, there was no difference with the master.

But when I merged the function branch into this branch (which pretty much had the same state as master), it ended as follows:

* b0dc045 - (new-branch) refactored it. seems to work fine | * 4b89219 - (HEAD -> feature, origin/feature) refactored it. seems to work fine |/ * Merge branch 'master' into 'feature' |\ ... 

'master' is somewhere below ...

Anyway, git diff new-branch feature doesn't show diff ... but they got different hashes .....

What things can I check to really see where they really differ?

Update:

I think that aspects of the history of the branch are included in the data set generating the hash. This explains the discrepancy.

So I did a quick and dirty trick.

 $ diff <(git log new-branch) <(git log feature) 1c1 < commit b0dc045b82cfc2f7060ccd3b28dd1b1ca1cf2a59 --- > commit 4b8921960cc8f1d42e3e4d1b505228a2dc0c0638 

This shows that the hash is different on the first line. This is the mysterious part. It also shows that the remaining 24 thousand lines of git log are identical.

+5
source share
2 answers

This is because the identifiers commit, time, author, and parent commit are part of the hash. This ensures that no one can change these fields after the commit is published, and further development has been done on top of it.

But, of course, it also allows you to re-affirm the same state with a large number of different authors, to record time, messages and stories as you please. Each time you get a different hash, and thus a different commit that has no difference in content.

+2
source

credit goes to @larsks for teams

 $ git cat-file -p new-branch; git cat-file -p feature; tree 26e6e56076b5578100857218df0cbed7fcab10a3 parent 72f868f7fd45ecabef78cab23f120d48a04bf38d author Steven Lu (PuTTY Win7 on Centos 7 VM Feb26[tmux]) < stevenlu443@gmail.com > 1439228778 -0400 committer Steven Lu (Centos 7 VM Feb26) < stevenlu443@gmail.com > 1439230770 -0400 refactored it. seems to work fine tree 26e6e56076b5578100857218df0cbed7fcab10a3 parent 72f868f7fd45ecabef78cab23f120d48a04bf38d author Steven Lu (PuTTY Win7 on Centos 7 VM Feb26[tmux]) < stevenlu443@gmail.com > 1439228778 -0400 committer Steven Lu (Centos 7 VM Feb26) < stevenlu443@gmail.com > 1439228778 -0400 refactored it. seems to work fine 

Delta is in new-branch committer time.

This is thaaaaazi maaaaan.

+2
source

All Articles