如何使 git status 仅显示暂存文件
我想获取仅包含暂存文件名的列表。我找不到 git status
命令的 --name-only
的等效标志。什么是好的替代方案?
文件列表将通过管道传输到 php -l(PHP lint 语法检查器)。
解决方案:完整命令
git diff --name-only --cached | xargs -l php -l
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?
The file list will be piped to php -l
(PHP lint syntax checker).
Solution: the complete command
git diff --name-only --cached | xargs -l php -l
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
使用
git diff --name-only
(使用--cached
获取暂存文件)Use
git diff --name-only
(with--cached
to get the staged files)接受的答案不会让您知道发生了什么样的变化。
是的,如果您不是语法检查器,而是一个普通人,拥有一个充满未暂存文件的存储库,并且您仍然想知道暂存文件会发生什么 - 还有另一个命令:
这会导致类似以下内容:
显然,该文件已暂存,以及
git commit
之后:deleted_file
将被删除,将添加
new_file
,renamed_file
将成为renamed_to
。以下是短格式输出的说明: https://git-scm.com/docs /git-status#_short_format
The accepted answer won't let you know what kind of changes were 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:
which leads to something like:
Obviously, this files were staged, and after
git commit
:deleted_file
will be deleted,new_file
will be added,renamed_file
will become arenamed_to
.Here is an explanation of short-format output: https://git-scm.com/docs/git-status#_short_format
中设置了以下别名
受到 @coffman21 的回答的启发,我在我的
.zshrc
或它 可能对其他人有用。因此将其添加到答案堆栈中。
Inspired by @coffman21's answer I have setup the following alias in my
.zshrc
or
It might be of use to anyone else. So adding it to the stack of answers.
查看代码更改的暂存文件
或使用
--cached
(它是--staged
的同义词)或仅查看没有代码更改的文件名
git-diff 手册
to view staged files with code changes
or using
--cached
which is synonym for--staged
or to view only file names without code changes
git-diff manual
要查看哪些文件已暂存,
To view which files are staged ,
仅显示暂存文件
- -porcelain
用于解析友好的输出--untracked-files=all
显示所有“未跟踪”文件。显示暂存以供提交的文件。grep '^[A|M|D|R]'
过滤以下文件的输出^
从换行符开头匹配。一行的第一个字符表示暂存区域中的状态,第二个字符表示工作树中的状态。添加了
M
已修改D
已删除R
已重命名这是基于 此评论
Show only staged files
--porcelain
for parsing-friendly output--untracked-files=all
show all "untracked" files. Shows the files that are staged for commit.grep '^[A|M|D|R]'
filter the output for files that are^
Match from the start of a newline. The first character of a line indicates the status in the staging area, the second in the working tree.A
addedM
modifiedD
deletedR
renamedThis was based on this comment
来自@velocity
git diff --staged 正是我想要的。如果有人希望将其变成 bashrc 中的 git ds 之类的快捷方式,请参阅以下示例:
from @velocity
git diff --staged
is exactly what I wanted. If anyone is looking to make this into a shortcut likegit ds
in your bashrc please see this example:您可以使用 git 命令
该命令将列出仅已暂存的文件的名称
You can use the git command
This command will list you the name of files that has been staged only