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

岁酱吖の 提交于 2019-12-04 18:09:54

问题


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.


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/41245475/differences-between-the-staged-and-unstaged-versions-of-the-same-file-using-dif

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!