如何在Git中显示未提交的更改?
我SFTW'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>...]'
Run Code Online (Sandbox Code Playgroud)
Cod*_*ard 290
如何在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
:
Aas*_*set 35
您已经进行了更改(可能是通过运行git add
),因此为了获得它们的差异,您需要运行:
git diff --cached
Run Code Online (Sandbox Code Playgroud)
(普通版git diff
仅显示未分级的更改.)
Ale*_*vić 10
对我来说,唯一有效的是
git diff HEAD
Run Code Online (Sandbox Code Playgroud)
包括暂存文件,git diff --cached
仅显示暂存文件。