How to make git status show only staged files

喜夏-厌秋 提交于 2019-12-17 08:34:09

问题


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

回答1:


Use git diff --name-only (with --cached to get the staged files)




回答2:


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:

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.

Here is an explanation of short-format output: https://git-scm.com/docs/git-status#_short_format



来源:https://stackoverflow.com/questions/4524998/how-to-make-git-status-show-only-staged-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!