git log -p vs. git show vs. git diff git log -p vs. git show vs. git diff git git

git log -p vs. git show vs. git diff


git log A B shows the history of both commits A and B (basically generating a union set of each commits' history). Usually you want git log A..B, which can also be written as git log ^B A (show everything reachable from A, but not (^) from B). This range can also be empty (for instance B..A would be empty, since every commit reachable from B is also reachable from A). Therefore, you also get no output from git log when used with the "wrong" arguments.

git show is a very versatile command and produces different output depending on its arguments. You can pass one or several commits and it will show you the commit information (authorship, timestamp, commit message, diff from previous commit). Commit ranges such as a..d will be resolved and each commit is shown individually. You can also pass a path and git show will show you the file's contents. You can also specify a file at a certain revision with the syntax commit:path/to/file. If you pass a directory, git show will display the commit information of the last commit changing that directory.

git diff generally expects two trees or two files to compare. (It can also take no arguments and compare the index/staging area instead). A commit is automatically unwrapped into its corresponding tree (a tree object describes a certain state of the repository). The syntax A..B is silently resolved to A B for the diff case and will show the changes required to get from commit/tree A to B

The range A...B means "every commit reachable from A or B, but not from both".

  • When used with git log it will show you those commits and it mostly only makes sense when used with diverged branches, i.e. "show every that's different between the two, but hide those commits which both branches have in common".
  • For git diff this syntax is syntactic sugar for git diff $(git merge-base A B) B, i.e. "changes in B since the history of A diverged.
  • With git show you will simply get commit information for each single commit in that range.

If anything's still unclear let me know in the comments.


Here's the output the repository you posted in your original question:

$ git init Initialized empty Git repository in ...$  cd SO$ ls$ echo a > a$ git add a$ git commit[master (root-commit) 7b66fe5] initial commit 1 file changed, 1 insertion(+) create mode 100644 a$ git tag a$ echo b >> a$ echo b > b$ git add a b$ git commit[master ee884fe] commit b 2 files changed, 2 insertions(+) create mode 100644 b$ git tag b$ echo c >> a$ echo c >> b$ echo c > c$ git add a b c$ git commit[master 8abaaff] commit c 3 files changed, 3 insertions(+) create mode 100644 c$ git tag c$ echo d >> a$ echo d > b$ git add a b$ git commit[master 08adc85] commit d 2 files changed, 2 insertions(+), 2 deletions(-)$ git tag d$ git log -p b d --commit 08adc8512e63588e6f01533b2a0f762342521b05Author: ...Date:   Mon Sep 1 17:22:06 2014 +0200    commit ddiff --git a/a b/aindex de98044..d68dd40 100644--- a/a+++ b/a@@ -1,3 +1,4 @@ a b c+ddiff --git a/b b/bindex 9ddeb5c..4bcfe98 100644--- a/b+++ b/b@@ -1,2 +1 @@-b-c+dcommit 8abaaff681be0bcaa16c946feb2989959348c9f4Author: ...Date:   Mon Sep 1 17:21:40 2014 +0200    commit cdiff --git a/a b/aindex 422c2b7..de98044 100644--- a/a+++ b/a@@ -1,2 +1,3 @@ a b+cdiff --git a/b b/bindex 6178079..9ddeb5c 100644--- a/b+++ b/b@@ -1 +1,2 @@ b+cdiff --git a/c b/cnew file mode 100644index 0000000..f2ad6c7--- /dev/null+++ b/c@@ -0,0 +1 @@+ccommit ee884fea5d0266280845348175ac0af5083a9bbfAuthor: ...Date:   Mon Sep 1 17:21:05 2014 +0200    commit bdiff --git a/a b/aindex 7898192..422c2b7 100644--- a/a+++ b/a@@ -1 +1,2 @@ a+bdiff --git a/b b/bnew file mode 100644index 0000000..6178079--- /dev/null+++ b/b@@ -0,0 +1 @@+bcommit 7b66fe5999039c53ffbe5a5ffe07c13a5c213455Author: ...Date:   Mon Sep 1 17:20:39 2014 +0200    initial commitdiff --git a/a b/anew file mode 100644index 0000000..7898192--- /dev/null+++ b/a@@ -0,0 +1 @@+a$ git show b d --commit ee884fea5d0266280845348175ac0af5083a9bbfAuthor: ...Date:   Mon Sep 1 17:21:05 2014 +0200    commit bdiff --git a/a b/aindex 7898192..422c2b7 100644--- a/a+++ b/a@@ -1 +1,2 @@ a+bdiff --git a/b b/bnew file mode 100644index 0000000..6178079--- /dev/null+++ b/b@@ -0,0 +1 @@+bcommit 08adc8512e63588e6f01533b2a0f762342521b05Author: ...Date:   Mon Sep 1 17:22:06 2014 +0200    commit ddiff --git a/a b/aindex de98044..d68dd40 100644--- a/a+++ b/a@@ -1,3 +1,4 @@ a b c+ddiff --git a/b b/bindex 9ddeb5c..4bcfe98 100644--- a/b+++ b/b@@ -1,2 +1 @@-b-c+d$ git diff b d --diff --git a/a b/aindex 422c2b7..d68dd40 100644--- a/a+++ b/a@@ -1,2 +1,4 @@ a b+c+ddiff --git a/b b/bindex 6178079..4bcfe98 100644--- a/b+++ b/b@@ -1 +1 @@-b+ddiff --git a/c b/cnew file mode 100644index 0000000..f2ad6c7--- /dev/null+++ b/c@@ -0,0 +1 @@+c$ git log -p d b --commit 08adc8512e63588e6f01533b2a0f762342521b05Author: ...Date:   Mon Sep 1 17:22:06 2014 +0200    commit ddiff --git a/a b/aindex de98044..d68dd40 100644--- a/a+++ b/a@@ -1,3 +1,4 @@ a b c+ddiff --git a/b b/bindex 9ddeb5c..4bcfe98 100644--- a/b+++ b/b@@ -1,2 +1 @@-b-c+dcommit 8abaaff681be0bcaa16c946feb2989959348c9f4Author: ...Date:   Mon Sep 1 17:21:40 2014 +0200    commit cdiff --git a/a b/aindex 422c2b7..de98044 100644--- a/a+++ b/a@@ -1,2 +1,3 @@ a b+cdiff --git a/b b/bindex 6178079..9ddeb5c 100644--- a/b+++ b/b@@ -1 +1,2 @@ b+cdiff --git a/c b/cnew file mode 100644index 0000000..f2ad6c7--- /dev/null+++ b/c@@ -0,0 +1 @@+ccommit ee884fea5d0266280845348175ac0af5083a9bbfAuthor: ...Date:   Mon Sep 1 17:21:05 2014 +0200    commit bdiff --git a/a b/aindex 7898192..422c2b7 100644--- a/a+++ b/a@@ -1 +1,2 @@ a+bdiff --git a/b b/bnew file mode 100644index 0000000..6178079--- /dev/null+++ b/b@@ -0,0 +1 @@+bcommit 7b66fe5999039c53ffbe5a5ffe07c13a5c213455Author: ...Date:   Mon Sep 1 17:20:39 2014 +0200    initial commitdiff --git a/a b/anew file mode 100644index 0000000..7898192--- /dev/null+++ b/a@@ -0,0 +1 @@+a$ git show d b --commit 08adc8512e63588e6f01533b2a0f762342521b05Author: ...Date:   Mon Sep 1 17:22:06 2014 +0200    commit ddiff --git a/a b/aindex de98044..d68dd40 100644--- a/a+++ b/a@@ -1,3 +1,4 @@ a b c+ddiff --git a/b b/bindex 9ddeb5c..4bcfe98 100644--- a/b+++ b/b@@ -1,2 +1 @@-b-c+dcommit ee884fea5d0266280845348175ac0af5083a9bbfAuthor: ...Date:   Mon Sep 1 17:21:05 2014 +0200    commit bdiff --git a/a b/aindex 7898192..422c2b7 100644--- a/a+++ b/a@@ -1 +1,2 @@ a+bdiff --git a/b b/bnew file mode 100644index 0000000..6178079--- /dev/null+++ b/b@@ -0,0 +1 @@+b$ git diff d b --diff --git a/a b/aindex d68dd40..422c2b7 100644--- a/a+++ b/a@@ -1,4 +1,2 @@ a b-c-ddiff --git a/b b/bindex 4bcfe98..6178079 100644--- a/b+++ b/b@@ -1 +1 @@-d+bdiff --git a/c b/cdeleted file mode 100644index f2ad6c7..0000000--- a/c+++ /dev/null@@ -1 +0,0 @@-c$ git log -p b..d --commit 08adc8512e63588e6f01533b2a0f762342521b05Author: ...Date:   Mon Sep 1 17:22:06 2014 +0200    commit ddiff --git a/a b/aindex de98044..d68dd40 100644--- a/a+++ b/a@@ -1,3 +1,4 @@ a b c+ddiff --git a/b b/bindex 9ddeb5c..4bcfe98 100644--- a/b+++ b/b@@ -1,2 +1 @@-b-c+dcommit 8abaaff681be0bcaa16c946feb2989959348c9f4Author: ...Date:   Mon Sep 1 17:21:40 2014 +0200    commit cdiff --git a/a b/aindex 422c2b7..de98044 100644--- a/a+++ b/a@@ -1,2 +1,3 @@ a b+cdiff --git a/b b/bindex 6178079..9ddeb5c 100644--- a/b+++ b/b@@ -1 +1,2 @@ b+cdiff --git a/c b/cnew file mode 100644index 0000000..f2ad6c7--- /dev/null+++ b/c@@ -0,0 +1 @@+c$ git show b..d --commit 08adc8512e63588e6f01533b2a0f762342521b05Author: ...Date:   Mon Sep 1 17:22:06 2014 +0200    commit ddiff --git a/a b/aindex de98044..d68dd40 100644--- a/a+++ b/a@@ -1,3 +1,4 @@ a b c+ddiff --git a/b b/bindex 9ddeb5c..4bcfe98 100644--- a/b+++ b/b@@ -1,2 +1 @@-b-c+dcommit 8abaaff681be0bcaa16c946feb2989959348c9f4Author: ...Date:   Mon Sep 1 17:21:40 2014 +0200    commit cdiff --git a/a b/aindex 422c2b7..de98044 100644--- a/a+++ b/a@@ -1,2 +1,3 @@ a b+cdiff --git a/b b/bindex 6178079..9ddeb5c 100644--- a/b+++ b/b@@ -1 +1,2 @@ b+cdiff --git a/c b/cnew file mode 100644index 0000000..f2ad6c7--- /dev/null+++ b/c@@ -0,0 +1 @@+c$ git diff b..d --diff --git a/a b/aindex 422c2b7..d68dd40 100644--- a/a+++ b/a@@ -1,2 +1,4 @@ a b+c+ddiff --git a/b b/bindex 6178079..4bcfe98 100644--- a/b+++ b/b@@ -1 +1 @@-b+ddiff --git a/c b/cnew file mode 100644index 0000000..f2ad6c7--- /dev/null+++ b/c@@ -0,0 +1 @@+c$ git log -p d..b --$ git show d..b --$ git diff d..b --diff --git a/a b/aindex d68dd40..422c2b7 100644--- a/a+++ b/a@@ -1,4 +1,2 @@ a b-c-ddiff --git a/b b/bindex 4bcfe98..6178079 100644--- a/b+++ b/b@@ -1 +1 @@-d+bdiff --git a/c b/cdeleted file mode 100644index f2ad6c7..0000000--- a/c+++ /dev/null@@ -1 +0,0 @@-c$ git log -p b...d --commit 08adc8512e63588e6f01533b2a0f762342521b05Author: ...Date:   Mon Sep 1 17:22:06 2014 +0200    commit ddiff --git a/a b/aindex de98044..d68dd40 100644--- a/a+++ b/a@@ -1,3 +1,4 @@ a b c+ddiff --git a/b b/bindex 9ddeb5c..4bcfe98 100644--- a/b+++ b/b@@ -1,2 +1 @@-b-c+dcommit 8abaaff681be0bcaa16c946feb2989959348c9f4Author: ...Date:   Mon Sep 1 17:21:40 2014 +0200    commit cdiff --git a/a b/aindex 422c2b7..de98044 100644--- a/a+++ b/a@@ -1,2 +1,3 @@ a b+cdiff --git a/b b/bindex 6178079..9ddeb5c 100644--- a/b+++ b/b@@ -1 +1,2 @@ b+cdiff --git a/c b/cnew file mode 100644index 0000000..f2ad6c7--- /dev/null+++ b/c@@ -0,0 +1 @@+c$ git show b...d --commit 08adc8512e63588e6f01533b2a0f762342521b05Author: ...Date:   Mon Sep 1 17:22:06 2014 +0200    commit ddiff --git a/a b/aindex de98044..d68dd40 100644--- a/a+++ b/a@@ -1,3 +1,4 @@ a b c+ddiff --git a/b b/bindex 9ddeb5c..4bcfe98 100644--- a/b+++ b/b@@ -1,2 +1 @@-b-c+dcommit 8abaaff681be0bcaa16c946feb2989959348c9f4Author: ...Date:   Mon Sep 1 17:21:40 2014 +0200    commit cdiff --git a/a b/aindex 422c2b7..de98044 100644--- a/a+++ b/a@@ -1,2 +1,3 @@ a b+cdiff --git a/b b/bindex 6178079..9ddeb5c 100644--- a/b+++ b/b@@ -1 +1,2 @@ b+cdiff --git a/c b/cnew file mode 100644index 0000000..f2ad6c7--- /dev/null+++ b/c@@ -0,0 +1 @@+c$ git diff b...d --diff --git a/a b/aindex 422c2b7..d68dd40 100644--- a/a+++ b/a@@ -1,2 +1,4 @@ a b+c+ddiff --git a/b b/bindex 6178079..4bcfe98 100644--- a/b+++ b/b@@ -1 +1 @@-b+ddiff --git a/c b/cnew file mode 100644index 0000000..f2ad6c7--- /dev/null+++ b/c@@ -0,0 +1 @@+c$ git log -p d...b --commit 08adc8512e63588e6f01533b2a0f762342521b05Author: ...Date:   Mon Sep 1 17:22:06 2014 +0200    commit ddiff --git a/a b/aindex de98044..d68dd40 100644--- a/a+++ b/a@@ -1,3 +1,4 @@ a b c+ddiff --git a/b b/bindex 9ddeb5c..4bcfe98 100644--- a/b+++ b/b@@ -1,2 +1 @@-b-c+dcommit 8abaaff681be0bcaa16c946feb2989959348c9f4Author: ...Date:   Mon Sep 1 17:21:40 2014 +0200    commit cdiff --git a/a b/aindex 422c2b7..de98044 100644--- a/a+++ b/a@@ -1,2 +1,3 @@ a b+cdiff --git a/b b/bindex 6178079..9ddeb5c 100644--- a/b+++ b/b@@ -1 +1,2 @@ b+cdiff --git a/c b/cnew file mode 100644index 0000000..f2ad6c7--- /dev/null+++ b/c@@ -0,0 +1 @@+c$ git show d...b --commit 08adc8512e63588e6f01533b2a0f762342521b05Author: ...Date:   Mon Sep 1 17:22:06 2014 +0200    commit ddiff --git a/a b/aindex de98044..d68dd40 100644--- a/a+++ b/a@@ -1,3 +1,4 @@ a b c+ddiff --git a/b b/bindex 9ddeb5c..4bcfe98 100644--- a/b+++ b/b@@ -1,2 +1 @@-b-c+dcommit 8abaaff681be0bcaa16c946feb2989959348c9f4Author: ...Date:   Mon Sep 1 17:21:40 2014 +0200    commit cdiff --git a/a b/aindex 422c2b7..de98044 100644--- a/a+++ b/a@@ -1,2 +1,3 @@ a b+cdiff --git a/b b/bindex 6178079..9ddeb5c 100644--- a/b+++ b/b@@ -1 +1,2 @@ b+cdiff --git a/c b/cnew file mode 100644index 0000000..f2ad6c7--- /dev/null+++ b/c@@ -0,0 +1 @@+c$ git diff d...b --$