[英]Before pushing to a remote git repo, is there a way of getting a list of all the files that would get pushed (without parsing the call to git status)?
I am trying to avoid the need to parse the output of "git status".我试图避免解析“git status”的 output 的需要。 Is there a command that will return a list of all the committed files that will get pushed on the next "git push" command?
是否有一个命令会返回所有已提交文件的列表,这些文件将在下一个“git push”命令中被推送?
You should try git diff --stat --cached origin/<<branch name>>
您应该尝试
git diff --stat --cached origin/<<branch name>>
Example: git diff --stat --cached origin/master
示例:
git diff --stat --cached origin/master
The --stat
generates a diffstat. --stat
生成差异统计。 The --cached
is to view the changes you staged. --cached
是查看您暂存的更改。
Let me know if this works.让我知道这个是否奏效。
Short answer简答
git log --pretty=format:"" --name-only @{upstream}.. | sort -u
Explanation解释
--pretty=format:""
to suppress commit info --pretty=format:""
抑制提交信息
--name-only
asks for the list of files --name-only
请求文件列表
@{upstream}
is a construct to describe the remote branch the current one is linked to. @{upstream}
是一种结构,用于描述当前分支链接到的远程分支。 It's not a placeholder, it's meant to be written as is.它不是占位符,它应该按原样编写。
@{upstream}..
(mind the ..
which makes it a range ) means everything on current branch but is unknown to the remote branch. @{upstream}..
(注意..
使它成为一个range )意味着当前分支上的所有内容,但远程分支不知道。
Of course, it's more useful to have it sorted in case you have many commits modifying the same files.当然,如果您有许多提交修改相同的文件,将其排序更有用。 Use
| sort -u
使用
| sort -u
| sort -u
for this purpose. | sort -u
为此目的。
Final note : Make it an alias!最后注意:让它成为一个别名!
# pf = Push Files (could be whatever else you prefer)
git config --global alias.pf '!git log --pretty=format:"" --name-only @{upstream}.. | sort -u'
# then just
git pf
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.