Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Why does git show use two + or - symbols (i.e. ++ and --) if the thing you're show'ing is a stash? It looks like this:

diff --cc test.txt
index fe9fc5a,fe9fc5a..5b776c1
--- a/test.txt
+++ b/test.txt
@@@ -1,2 -1,2 +1,2 @@@
--Hello, world!
--Goodbye, world!
++Hello, universe!
++Goodbye, universe!

Just curious...


To reproduce:

$ git init 
Initialized empty Git repository in /tmp/test/.git/
$ cat > test.txt <<EOF
Hello, world!
Goodbye, world!
EOF
$ git add test.txt
$ git commit -m 'initial commit'
[master (root-commit) b6ad668] initial commit
 1 file changed, 2 insertions(+)
 create mode 100644 test.txt
$ sed -i 's/world/universe/' test.txt 
$ git stash 
Saved working directory and index state WIP on master: b6ad668 initial commit
HEAD is now at b6ad668 initial commit
$ git show stash@{0}
commit d8b13c608945ffd3c5705a1960f96616b603d134
Merge: b6ad668 58aaf4f
Author: Mitchel Humpherys <mitchelh@codeaurora.org>
Date:   Wed Jan 30 17:47:02 2013 -0800

    WIP on master: b6ad668 initial commit

diff --cc test.txt
index fe9fc5a,fe9fc5a..5b776c1
--- a/test.txt
+++ b/test.txt
@@@ -1,2 -1,2 +1,2 @@@
--Hello, world!
--Goodbye, world!
++Hello, universe!
++Goodbye, universe!
share|improve this question
    
+1: Good question, clear instructions to reproduce. –  chepner Feb 4 '13 at 14:12

1 Answer 1

up vote 2 down vote accepted

The diff program can show you differences between more than two files, in which case multiple columns of "+" and "-" are used. The stash stores both the changes to the working directory that were staged, and the changes that were not staged. The resulting diff gives you information about both.

See git help diff, in the section COMBINED DIFF FORMAT. It will explain how each column of plus and minuses show the differences between two different files. Here, the first column shows the difference between HEAD and the working directory at the time of the stash, and the second column the difference between the index and the working directory.

To see the difference, modify your example to stage one of the changes before doing the stash, for example:

$ git init
$ # create the file
$ git commit -a -m 'initial commit'
$ # edit the first line of the file
$ git add test.txt
$ # edit the second line of the file
$ git stash
$ git stash show
- Hello, world!
- Goodbye, world!
+ Hello, universe!
 -Goodbye, world!
++Goodbye, universe!

From the first column, you can see that both lines have changed since the last commit, but only "Goodbye, universe"! is changed between the index and the working directory.

share|improve this answer
1  
Bonus points for the man reference, thanks! –  mgalgs Feb 5 '13 at 4:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.