【问题标题】:Finding the most frequent committer to a specific file查找特定文件的最频繁提交者
【发布时间】:2017-04-22 04:31:47
【问题描述】:

给定 git 存储库中的特定文件,我将如何查找该文件中最常见的提交者?

【问题讨论】:

  • 这里的“频繁”是什么意思?比其他任何人或台词都多的时代?
  • 好问题。你能把两个都发吗?

标签: git


【解决方案1】:
$ git log --follow <file> | grep "Author: " | sort | uniq -c | sort

一些解释:

git log --follow &lt;file&gt; - 将日志限制到特定文件,遵循此文件的所有重命名

grep "Author:" | sort - 只取与作者和组作者在一起的行

uniq -c | sort - 按组统计作者并再次排序,所以最常见的在第一行

:)

【讨论】:

    【解决方案2】:
    git log --format="%cn" | sort | uniq -c | sort -nr
    

    获取每个commit的committer name,group和count,降序排序。

    【讨论】:

      【解决方案3】:

      您可以为此使用git shortlog

      git shortlog -sn -- path/to/file
      

      这将打印出路径的作者列表,按提交计数排序和前缀。

      通常,此命令用于获取更改的快速摘要,例如生成变更日志。使用-s,更改摘要被禁止,只留下作者姓名。并与-n配对,输出按提交计数排序。

      当然,除了文件路径之外,您还可以使用目录路径来查看对该路径的提交。如果您完全离开这条路,git shortlog -sn 会为您提供整个存储库的统计信息。

      【讨论】:

      • 很好的答案,比我的要好 :) 但您可能需要额外的 --follow 来检测重命名。
      • 谢谢!换行数怎么样?
      • @LeoNatan 这是一个不同的问题,而且有点复杂;您可以解析来自 git log --shortstat 的输出,类似于 Patryk 的回答。但请查看this question 了解更多想法。
      【解决方案4】:

      您可以根据每个用户的提交次数来缩短输出。

      $ git shortlog -sen <file/path>
      
      Here,
      -s for commit summary
      -e for email
      -n short by number instead of alphabetic order  
      
      // more info
      $ git shortlog --help
      

      【讨论】:

        猜你喜欢
        • 2018-10-01
        • 2018-08-08
        • 2021-12-05
        • 1970-01-01
        • 2013-11-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多