Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+19 votes

Is there any difference between git diff HEAD~2 HEAD and git diff HEAD HEAD~2? or the order doesn't matter?

asked in CSC305 Fall 2022 by (1 point)
recategorized by

1 Answer

+9 votes
 
Best answer

They are a little different in how the "differences" are presented to you.

Let's suppose that the last commit added

System.out.println("Pelican");

And the commit before that added:

System.out.println("Coot");

Then git diff HEAD~2 HEAD will show those lines with plusses (things that were added), whereas git diff HEAD HEAD~1 will show those lines with minuses (things that were removed).

i.e. "what changed to get from HEAD~2 to HEAD" or "what would change if we started at HEAD and went back to HEAD~2"

answered by (508 points)
selected by
...