Differences between the staged and unstaged versions of the same file, using difftool [duplicate]
Asked Answered
H

2

17

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.

Heavyweight answered 20/12, 2016 at 15:10 Comment(2)
It's the same file.Repeat
@MarounMaroun Yes, that's the point. Git concentrates on the changes to a file, not the file itself. See this question: #24838341Heavyweight
B
43

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
Brig answered 20/12, 2016 at 19:19 Comment(1)
Thanks a lot! That's the answer I was looking for.Heavyweight
R
1

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

Rie answered 20/12, 2016 at 15:17 Comment(4)
This does not answer my question.Heavyweight
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?Rie
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.Heavyweight
I see, makes sense. Thanks for the clarification @DrKaoliN.Rie

© 2022 - 2024 — McMap. All rights reserved.