0

Let's say that I have 2 commits, initial_commit which is my intial commit and added_file in which I added a file

git diff <initial_commit> <added_file>

git will show me that a file was added, however, I often confuse in which order I'm supposed to input the commits to git diff and often end up with

git diff <added_file> <initial_commit>

and then it will look like a file was actually removed. I'm fully aware that git is simply doing what I'm asking it to do but my question is, is there some way for me to tell git to "figure out" which of the commits is the older one and always do a diff where the older commit is compared to the newer commit? I have read through the manpage without finding anything, but I'll admit I don't have that much experience in reading those so I might've missed it

Richo
  • 751
  • 7
  • 17

1 Answers1

0

You can't easily tell which is the 'newer' as one may not be the parent of a child. But the information is there at the top of the diff.

amb@nimrod-ubuntu:~/git-publish/git-publish$ git diff remotes/origin/master remotes/github/master
diff --git a/git-publish b/git-publish
index 96f05d3..38d4200 100755
--- a/git-publish
+++ b/git-publish

What that tells you is that if you call the first parameter to git diff a, and the second b, then the patch is something that transforms a to b, i.e. a line marked - is in a and being removed, and a line marked + is in b having been added.

abligh
  • 24,573
  • 4
  • 47
  • 84