繁体   English   中英

在推送到远程 git 回购之前,有没有办法获取所有将被推送的文件的列表(不解析对 git 状态的调用)?

[英]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)?

我试图避免解析“git status”的 output 的需要。 是否有一个命令会返回所有已提交文件的列表,这些文件将在下一个“git push”命令中被推送?

您应该尝试git diff --stat --cached origin/<<branch name>>

示例: git diff --stat --cached origin/master

--stat生成差异统计。 --cached是查看您暂存的更改。

让我知道这个是否奏效。

简答

git log --pretty=format:"" --name-only @{upstream}.. | sort -u

解释

--pretty=format:""抑制提交信息

--name-only请求文件列表

@{upstream}是一种结构,用于描述当前分支链接到的远程分支。 它不是占位符,它应该按原样编写。

@{upstream}.. (注意..使它成为一个range )意味着当前分支上的所有内容,但远程分支不知道。

当然,如果您有许多提交修改相同的文件,将其排序更有用。 使用| sort -u | sort -u为此目的。


最后注意:让它成为一个别名!

# 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM