0 votes
1 view
in Devops and Agile by (25.5k 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 (42.6k 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

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...