Why git diff --name-only does not show any modified files?
请注意(我正在使用posh git):
1 2 | C:\xyz\git [master ↑2 +27 ~0 -0 !]> git diff --name-only C:\xyz\git [master ↑2 +27 ~0 -0 !]> |
27个文件夹未分页,每个文件夹都有一些文件。未进行任何更改。
为什么不显示任何文件?
编辑1
以下简单的文字说明了问题:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | C:\xyz> mkdir git Directory: C:\xyz Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 10/16/2018 1:20 PM git C:\xyz> cd git C:\xyz\git> git init Initialized empty Git repository in C:/xyz/git/.git/ C:\xyz\git [master]> echo hello > 1.txt C:\xyz\git [master +1 ~0 -0 !]> git diff --name-only C:\xyz\git [master +1 ~0 -0 !]> git status On branch master No commits yet Untracked files: (use"git add <file>..." to include in what will be committed) 1.txt nothing added to commit but untracked files present (use"git add" to track) C:\xyz\git [master +1 ~0 -0 !]> |
号
编辑2
根据https://git-scm.com/docs/git-diff:
1 | git diff [<options>] [--] [<path>…?] |
This form is to view the changes
you made relative to the index (staging area for the next commit). In
other words, the differences are what you could tell Git to further
add to the index but you still haven’t. You can stage these changes by
using git-add[1].
号
据我所知,这意味着上述文本中的
注意,
- 将一个提交与另一个提交进行比较
- 比较对索引的任何提交
- 比较对工作树的任何提交
- 将索引与工作树进行比较
正如您在编辑中所指出的,您选择的是最后一个选项。
当您选择将索引与工作树进行比较时,要比较的文件列表完全由索引内容控制。任何未跟踪的文件都将被完全忽略。这与
如果您希望Git知道文件存在,使用一种作为占位符的索引项,可以考虑使用
- "git diff" compares the index and the working tree. For paths
added with intent-to-add bit, the command shows the full contents
of them as added, but the paths themselves were not marked as new
files. They are now shown as new by default.
号