Order of commit arguments in git diff -


in order git command

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

compare different commits against each other? seems if want compare new against old 1 need do

git diff [--options] <new_commit> <old_commit> in order see current diff?

i git diff [--options] <old_commit> <new_commit>

but seems wrong?

when example

$ git diff `git rev-list --since="jun 30 2014" --reverse origin/master | head -1` `git rev-list --until="dec 31 2014" origin/master | head -1` --shortstat   1072 files changed, 389650 insertions(+), 39180 deletions(-) 

but when

$ git diff --stat `git rev-list --until="dec 31 2014" origin/master | head -1` 

i printout that:

384 files changed, 61255 insertions(+), 20526 deletions(-) 

which not near 300000. question if should insert new commit first , old commit sedond, like:

 $ git diff `git rev-list --until="dec 31 2014" origin/master | head -1`..`git rev-list --since="jun 30 2014" --reverse origin/master | head -1`  

i can't find documentation in order should insert commits in order see difference between new , old commit. perhaps can clarify me?

thanks in advance.

edit: reason i'm asking want

  1. know how many new lines of code has been added new commit given old commit, and

  2. i want calculate number of lines of code in new commit.

tl;dr

in following git-diff syntax,

git diff [--options] <commit> <commit> [--] [<path>...] 
  • the first <commit> corresponds base commit,
  • the second <commit> corresponds commit compare base commit.

using mathematically inspired notation,

git diff <x> <x+∆x> 

will show difference ∆x, whereas

git diff <x+∆x> <x> 

will show difference -∆x.

note that, because 2 commits need not ordered in way, either chronologically or topologically, calling them "old" , "new" (as do) bit misleading.

more details

you can learn great deal looking git-diff man page. under description section, you'll find

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

this view changes between 2 arbitrary <commit>.

granted, doesn't tell commit which, but, further down, under examples section, you'll find couple of illuminating examples:

git diff head^ head 

[...] compare version before last commit , last commit.

and

git diff topic...master 

[...]

changes occurred on master branch since when topic branch started off it.


Comments