git 如何列出所有已更改文件数的拉取请求

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40182366/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 12:22:36  来源:igfitidea点击:

how to list all pull request with count of files changed

gitgithubversion-controlcommitpull-request

提问by ankitd

I am looking for some command which tells me number of files committed in a single pull request. I would like to know count of files in a single pull request individual from beginning.

我正在寻找一些命令,它告诉我在单个拉取请求中提交的文件数。我想从一开始就知道单个拉取请求中的文件数。

Question explained in real life scenario: Let's say for some myProjectsomeone raised a pull request number 100which has changes in 15files.

在现实生活场景中解释的问题:假设myProject有人提出了一个拉取请求编号100,该编号在15文件中发生了变化。

I am looking for a command which list all pull request from 1 to 100 with count of changed files.

我正在寻找一个命令,它列出了从 1 到 100 的所有拉取请求以及更改文件的数量。

Please answer wrto Windows 7.

请回答 Windows 7。

i.e.

IE

  • PR Number 100 has changes in 10 files
  • PR Number 99 has changes in 5 files
  • PR Number 98 has changes in 6 files
  • PR Number 96 has changes in 22 files
  • -
  • -
  • -
  • -
  • PR Number 50 has changes in 7 files
  • .
  • .
  • .
  • .
  • PR Number 10 has changes in 2 files
  • .
  • .
  • .
  • .
  • PR Number 1 has changes in 23 files
  • PR Number 100 在 10 个文件中有更改
  • PR Number 99 在 5 个文件中有更改
  • PR Number 98 在 6 个文件中有更改
  • PR Number 96 有 22 个文件的变化
  • ——
  • ——
  • ——
  • ——
  • PR Number 50 在 7 个文件中有更改
  • .
  • .
  • .
  • .
  • PR Number 10 在 2 个文件中有更改
  • .
  • .
  • .
  • .
  • PR Number 1 在 23 个文件中有更改

回答by larsks

You can get a list of remote pull requests like this:

您可以像这样获取远程拉取请求列表:

git ls-remote origin 'pull/*/head'

(assuming that originis the name of your GitHub remote)

(假设这origin是您的 GitHub 遥控器的名称)

For a given commit, you can get a list of changed files like this:

对于给定的提交,您可以获得更改文件的列表,如下所示:

git show --pretty=format:'' --name-only <ref>

You can put the above information together into a shell script:

你可以把上面的信息放到一个shell脚本中:

git ls-remote origin 'pull/*/head' | awk '{print }' |
while read ref; do
  pr=$(echo $ref | cut -d/ -f3)
  git fetch origin $ref > /dev/null
  files_changed=$(git show --pretty=format:'' --name-only FETCH_HEAD|wc -l)
  echo "PR number $pr has changes in $files_changed files"
done

Which produces output on stdout like:

它在 stdout 上产生输出,如:

PR number 1 has changes in 4 files
PR number 10 has changes in 1 files
PR number 11 has changes in 4 files
PR number 12 has changes in 7 files
PR number 13 has changes in 5 files

(there is also output on stderr, which you can take care of with standard shell i/o redirection).

(stderr 上也有输出,您可以使用标准 shell 输入/输出重定向来处理)。

This pretty much does what you want, with one major caveat: pull requests persist as refs in your remote GitHub repository even after they have been closed, so this will always iterate over every available pull request, past and present.

这几乎可以满足您的要求,但有一个主要警告:拉取请求即使在关闭后仍作为参考保留在远程 GitHub 存储库中,因此这将始终迭代过去和现在的每个可用拉取请求。

You could work around this by caching locally information about the highest PR number you've previously checked, and then skipping all PRs that are lower.

您可以通过在本地缓存有关您之前检查过的最高 PR 编号的信息,然后跳过所有较低的 PR 来解决此问题。

回答by Ted

This works for bitbucket

这适用于 bitbucket

git ls-remote origin 'pull-requests/*'