【问题标题】:Get the file that modified most of times between two commits in Git获取 Git 中两次提交之间修改次数最多的文件
【发布时间】:2015-01-13 10:44:32
【问题描述】:

最近,我发现我正在处理的项目的错误比我预期的要多,我想找出在我们的 sprint 中哪些文件更改最多。

我可以这样做,但它只显示更改了哪些文件,而不显示更改了多少次

git diff --name-only SHA1 SHA2

请让我朝着正确的方向写一个脚本来显示两次提交之间哪些文件更改最多。

提前致谢。

【问题讨论】:

  • 你的意思是改变了行数?

标签: git shell powershell


【解决方案1】:
git log --name-only --format=%n SHA1..SHA2 | Group-Object | Format-Table Count,Name

使用--format=%n 为每个提交获取一个空白行,以将它们全部折叠到一个排序和计数的条目中。然后每个文件的文件名在Group-Object 中整理在一起。

| sort | uniq -chere 的 Powershell 翻译。

【讨论】:

    【解决方案2】:

    git-diff documentation 中,您需要--stat--numstat,具体取决于您希望输出的外观:

      git diff --stat hash1 hash2
    
      .file1.un~ | Bin 0 -> 948 bytes
      .file2.un~ | Bin 0 -> 523 bytes
      file1      |  25 +++++++++++++++++++++++++
      file2      |   8 ++++++++
      4 files changed, 33 insertions(+)
    

    或者

     git diff --numstat hash1 hash2
    
     -       -       .file1.un~
     -       -       .file2.un~
     25      0       file1
     8       0       file2
    

    【讨论】:

      【解决方案3】:

      最近 10 次提交的示例。随意更改它为您的需要。如果遇到超过 2 位的情况,请相应更改 sprintf 表达式 "%02d"

      git log --name-only --pretty="%n" HEAD~10..HEAD |
      egrep '.' |
      sort |
      uniq -c  |
      perl -pe 's/([0-9]+)/sprintf("%02d",$1)/e' |
      sort -r |
      less
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-12-07
        • 2011-03-09
        • 1970-01-01
        • 2011-08-05
        • 1970-01-01
        • 2011-02-01
        相关资源
        最近更新 更多