In Git, how could I compare the same file between two different commits (not contiguous) on the same branch (master for example)?
I'm searching for a compare feature like the one in Visual SourceSafe (VSS) or Team Foundation Server (TFS).
Is it possible in Git?
The git diff command displays the differences between files in two commits or between a commit and your current repository. You can see what text has been added to, removed from, and changed in a file. By default, the git diff command displays any uncommitted changes to your repository.
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.
In order to see the commit differences between two branches, use the “git log” command and specify the branches that you want to compare. Note that this command won't show you the actual file differences between the two branches but only the commits.
From the git-diff
manpage:
git diff [--options] <commit> <commit> [--] [<path>...]
For instance, to see the difference for a file "main.c" between now and two commits back, here are three equivalent commands:
$ git diff HEAD^^ HEAD main.c $ git diff HEAD^^..HEAD -- main.c $ git diff HEAD~2 HEAD -- main.c
You can also compare two different files in two different revisions, like this:
git diff <revision_1>:<file_1> <revision_2>:<file_2>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With