To reprodoce this behaviour just init a new git repository, create a file, add and commit. Now edit this file again (no add, no commit this time) and stash. The result should look like this:
$ git log stash@{0} --graph --decorate
* commit C (refs/stash)
|\ Merge: A C
| | WIP on master: A init
| |
| * commit B
|/ index on master: A init
|
* commit A (HEAD, master)
init
The diff between A and C shows the expected result:
$ git diff stash@{0}^..stash@{0}
diff --git a/file b/file
index b1b7161..51bdcb4 100644
--- a/file
+++ b/file
@@ -1 +1,2 @@
+a new uncommited change
init
I would expect the same output for the command
$ git log stash@{0}
but there is no patch. Why does this happen? (This is not related to stashing: Same behaviour if you create the history using empty commit, no-ff, ...)
Why does this happen?
Because git log -1 -p
doesn't show the diff for any commit with multiple parents. Additional options are needed for that. Normally, you might want to pick git show
for showing one single commit along with the patch, which is mostly equivalent but adds --cc
as a default option. Explicitly adding that gets you a diff with git log
too.
There are other options for controlling the display of merge commits: you can use -c
to get a more verbose form of --cc
, -m
to get a regular diff to all parents (A and B), or combine that with --first-parent
to get a plain diff from A to C.