如何详细显示Git和一些Git差异中未提交的更改


202

如何显示Git中未提交的更改?

STFW'ed,这些命令不起作用:

teyan@TEYAN-THINK MINGW64 /d/nano/repos/PSTools/psservice (teyan/psservice)
$ git status
On branch teyan/psservice
Your branch is up-to-date with 'origin/teyan/psservice'.
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   psservice.c
        modified:   psservice.vcxproj.filters


teyan@TEYAN-THINK MINGW64 /d/nano/repos/PSTools/psservice (teyan/psservice)
$ git diff

teyan@TEYAN-THINK MINGW64 /d/nano/repos/PSTools/psservice (teyan/psservice)
$ git diff master
fatal: ambiguous argument 'master': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

Answers:


370

如何显示Git中未提交的更改

您要查找的命令是git diff

git diff -显示提交,提交和工作树等之间的更改


这是它可以使用的一些选项

git diff(无参数)
打印出您的工作目录和索引之间的差异。

git diff --cached
打印出索引和HEAD(当前提交)之间的差异。

git diff HEAD
打印出您的工作目录和HEAD 之间的差异。

git diff --name-only
仅显示已更改文件的名称。

git diff --name-status
仅显示更改文件的名称和状态

git diff --color-words
逐字差异而不是逐行。

这是以下示例的输出git diff --color-words

在此处输入图片说明


在此处输入图片说明


2
当您在末尾看到冒号提示时,表示git已经显示了第一页-按Enter键以逐步进行其他更改(例如您可以使用cat文件|更多信息)
NULL指针

42

您已经上演了更改(大概通过运行git add),因此为了获取它们的差异,您需要运行:

git diff --cached

(平原git diff将仅显示未分级的更改。)

例如: git diff缓存使用示例


By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.