15

Is there a way of viewing the differences between the staged and unstaged versions of the same file?

For example:

Changes to be committed:

    modified:   conf/application.conf

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   conf/application.conf

This happens when I stage a change and then I modify the file again, without staging it.

EDIT

The git status -vv command is not good enough, because I need to use the diff / difftool command. That's because in practice there are too many changes in too many files, and scrolling through all of them is not efficient. But diff / difftool allows me to specify the file I am interested in.

Guy Avraham
  • 3,482
  • 3
  • 38
  • 50
DrKaoliN
  • 1,346
  • 4
  • 25
  • 39
  • It's the same file. – Maroun Dec 20 '16 at 15:13
  • 1
    @MarounMaroun Yes, that's the point. Git concentrates on the changes to a file, not the file itself. See this question: https://stackoverflow.com/questions/24837841/git-can-a-file-be-both-staged-and-unstaged-for-commit – DrKaoliN Dec 21 '16 at 08:12

2 Answers2

39

git diff will show the difference between your workspace and the index. (the index is where the staged files live)

This may not seem obvious because we usually use git diff to see the changes in the workspace vs what is checked in. However, technically git diff shows workspace vs index, and if you haven't added changes to the index, then the index matches what you checked out.

  • to see workspace vs repo: git diff HEAD
  • to see index vs repos: git diff --cached (can also use --staged)
  • to see workspace vs index: git diff
Randy Leberknight
  • 1,363
  • 9
  • 17
1

If you run the command git status -vv you will see the textual changes of the file. See doc.

Jake Henningsgaard
  • 704
  • 1
  • 6
  • 16
  • This does not answer my question. – DrKaoliN Dec 21 '16 at 08:08
  • Can you elaborate @DrKaoliN, maybe I misunderstood. Running that command will show all the changes to `conf/application.conf` that have occurred since you staged it. Is that not the same thing as showing the difference between the staged and upstaged version of `conf/application.conf`? – Jake Henningsgaard Dec 21 '16 at 14:17
  • Well, that particular command does not help me because I need to use the `diff` or the `difftool` command, so that I can see those differences _just for the specified file_ i.e. I can type `git diff conf/application.conf` but typing `git status -vv conf/application.conf`, will still show me all the changes in the console. Because in practice I never have just one file modified, there are perhaps tens of files, with tens of modified lines of code, and scrolling for half a minute to find what I need is not efficient. But _technically_, your answer is correct, indeed. – DrKaoliN Dec 22 '16 at 07:50
  • I see, makes sense. Thanks for the clarification @DrKaoliN. – Jake Henningsgaard Dec 23 '16 at 18:50