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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35978550/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 04:00:58  来源:igfitidea点击:

How to show uncommitted changes in Git and some Git diffs in detail

gitgit-diff

提问by TD_Yan

How do I show uncommitted changes in Git?

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

I STFW'ed, and these commands are not working:

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>...]'

回答by CodeWizard

How to show uncommitted changes in Git

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

The command you are looking for is git diff.

您正在寻找的命令是git diff.

git diff- Show changes between commits, commit and working tree, etc

git diff- 显示提交、提交和工作树等之间的变化



Here are some of the options it expose which you can use

以下是它公开的一些您可以使用的选项

git diff(no parameters)
Print out differences between your working directory and the index.

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

git diff --cached:
Print out differences between the indexand HEAD (current commit).

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

git diff HEAD:
Print out differences between your working directoryand the HEAD.

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

git diff --name-only
Show only names of changed files.

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

git diff --name-status
Show only names and statusof changed files.

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

git diff --color-words
Word by word diff instead of line by line.

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

Here is a sample of the output for git diff --color-words:

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

enter image description here

在此处输入图片说明



enter image description here

在此处输入图片说明

回答by Aasmund Eldhuset

You have already staged the changes (presumably by running git add), so in order to get their diff, you need to run:

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

git diff --cached

(A plain git diffwill only show unstaged changes.)

(平原git diff只会显示未分阶段的更改。)

For example: Example git diff cached use

例如: git diff 缓存使用示例

回答by Aleksandar Pavi?

For me, the only thing which worked is

对我来说,唯一有效的是

git diff HEAD

including the staged files, git diff --cachedonly shows staged files.

包括暂存文件,git diff --cached只显示暂存文件。