如何让 git status 只显示暂存文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4524998/
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
How to make git status show only staged files
提问by Ward Bekker
I would like to get a list of only the staged filenames. I can't find the equivalent flag for --name-only
for the git status
command. What is a good alternative?
我想获得一个仅包含暂存文件名的列表。我找不到--name-only
该git status
命令的等效标志。什么是好的选择?
The file list will be piped to php -l
(PHP lint syntax checker).
文件列表将通过管道传输到php -l
(PHP lint 语法检查器)。
Solution: the complete command
解决方案:完整命令
git diff --name-only --cached | xargs -l php -l
回答by Ben Hymanson
Use git diff --name-only
(with --cached
to get the staged files)
使用git diff --name-only
(with--cached
获取暂存文件)
回答by coffman21
The accepted answer won't let you know what kind of changeswere there.
接受的答案不会让您知道那里发生了什么样的变化。
Yes, If you are not syntax checker but an ordinary person with a repository full of unstaged files, and you still want to know what will happen to staged files - there is another command:
是的,如果您不是语法检查员,而是一个存储库中充满未暂存文件的普通人,并且您仍然想知道暂存文件会发生什么 - 还有另一个命令:
git status --short | grep '^[MARCD]'
which leads to something like:
这导致类似的事情:
M dir/modified_file
A dir/new_file
R dir/renamed -> dir/renamed_to
C dir/copied_file
D dir/deleted_file
Obviously, this files were staged, and after git commit
:deleted_file
will be deleted,new_file
will be added,renamed_file
will become a renamed_to
.
很明显,这个文件被暂存了,之后git commit
:deleted_file
会被删除,new_file
会被添加,renamed_file
会变成renamed_to
.
Here is an explanation of short-format output: https://git-scm.com/docs/git-status#_short_format
以下是短格式输出的解释:https: //git-scm.com/docs/git-status#_short_format
回答by velocity
to view staged files with code changes
查看带有代码更改的暂存文件
git diff --staged
or using --cached which is synonym for --staged
或使用 --cached 这是 --staged 的同义词
git diff --cached
or to view only file names without code changes
或仅查看文件名而不更改代码
git diff --staged --name-only