Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (29.3k points)

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?

1 Answer

0 votes
by (50.2k points)

For this question, git diff manual page in the documentation gives you the syntax through which you can use 

git diff [--options] <commit> <commit> [--] [<path>...]

Now see the example which sees the difference between ‘yesh.c’ and previous commits.

git diff HEAD^^ HEAD yesh.c

git diff HEAD^^..HEAD -- yesh.c

git diff HEAD~2 HEAD -- yesh.c

Here these 3 commands will do the same which shows the difference between yesh.c and previous 2 commits. Hope this helps.

Reference: https://git-scm.com/docs/git-diff#Documentation/git-diff.txt-emgitdiffemltoptionsgtltcommitgtltcommitgt--ltpathgt82308203

Related questions

Browse Categories

...