Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to check if two different git commits are equal in content?

Tags:

git

I know that git tracks content and generates a sha based partially on the content. However, the sha is also based upon the parent commit. When I rebase a branch, because my commits now have a different ancestor, all of my commits have different shas.

But what I'm wondering, is there a way to compare two commits (or commit ranges) to see if content-wise, they are the same? This should also be able to tell if a binary change is the same as well.

I'm thinking if there was some way to get the sha for the content without the ancestor information incorporated, that might do it.

Thanks for any and all help,

like image 548
Nate Cavanaugh Avatar asked Jul 12 '12 19:07

Nate Cavanaugh


People also ask

Can we compare two commits in git?

You can also compare two arbitrary commits in your repository or its forks on GitHub in a two-dot diff comparison. To quickly compare two commits or Git Object IDs (OIDs) directly with each other in a two-dot diff comparison on GitHub, edit the URL of your repository's "Comparing changes" page.

How do you compare the differences between two commits?

To see the changes between two commits, you can use git diff ID1.. ID2 , where ID1 and ID2 identify the two commits you're interested in, and the connector .. is a pair of dots. For example, git diff abc123.. def456 shows the differences between the commits abc123 and def456 , while git diff HEAD~1..

How do I compare files between two commits in git?

You can compare files between two Git commits by specifying the name of the ref that refers to the commits you want to compare. A ref may be a commit ID or HEAD, which refers to the current branch. Let's compare two commits in our Git repository. The above command will perform a diff operation across our two commits.

How do I compare two commits in the same branch?

To compare any two commits in your branch, use the Ctrl key to select the two commits that you want to compare. Then right-click one of them and select Compare Commits.


2 Answers

You want the --cherry-mark option to git log which marks commits with an equals sign when their patch content is the same.

git log --decorate --graph --oneline --cherry-mark --boundary A...B

is a great way to compare the rebased branch B with the original branch A. I use this for checking that my commits made using git-tfs are still ok once TFS has been at them.

like image 67
patthoyts Avatar answered Oct 14 '22 21:10

patthoyts


https://stackoverflow.com/a/23527631/2630028

diff <(git show 123456) <(git show abcdef)

like image 40
solstice333 Avatar answered Oct 14 '22 23:10

solstice333