Thanatos
Thanatos

Reputation: 44354

git: Difference between two very similar commits?

I need to know why two commits are different. I have two commits, e2383d and 2c44ab, which are, apparently, since they have different hashes, different.

First, I know about git diff, and currently, I am trying git diff e2383d 2c44ab. It returns successfully, with no output. The two commits have:

Basically, my tree looks like this:

* ← stuff based on that commit
| * ← e2383d
* | ← 2c44ab
|/
* ← the common parent

I'm about to eliminate e2383d, but before I do, I'd like to make sure there isn't something important there. My understanding of git, however, was that if two "commits" were the same, they'd have the same hash, and thus my situation would not exist unless there was a difference between the two.

Another thing I've tried:

% diff <(git show 2c44ab) <(git show e2383d)  
1c1
< commit 2c44ab...
---
> commit e2383d...

Forgot that commits have >1 date on them. The following command showed (for me) the difference between my two commits:

% diff <(git show --pretty=fuller 2c44ab) <(git show --pretty=fuller e2383d)
1c1
< commit 2c44ab96bde429c9f345d8a12dfcf2278faa9333
---
> commit e2383d3164589bb3a8a679c9cb6bbe93ea41e2ee
5c5
< CommitDate: Wed Nov 23 17:06:40 2011 -0800
---
> CommitDate: Mon Nov 28 11:41:26 2011 -0800

The commit date for Monday, was the time at which I did a rebase. Now, why does git store this — seems to defeat the "These are the same commit, I'll fold them" behavior I expected.

Upvotes: 4

Views: 353

Answers (1)

Josh Lee
Josh Lee

Reputation: 177875

Two commits may have the same tree but different metadata. Any time a commit is amended, rebased, or cherry picked, the commit date will be updated and a new commit is written.

If git says that the diff between commits A and B is empty, but you’re still unsure, you can verify for yourself that they point to the same tree with

git rev-parse A^{tree} B^{tree}

which will list the names of their tree objects, or with

git cat-file -p A
git cat-file -p B

which will show the raw commit objects to you.

Upvotes: 2

Related Questions