在 Git 中查找更改最多的文件

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

Finding most changed files in Git

gitshell

提问by Sebastian

How can I show files in Git which change most often?

如何在 Git 中显示最常更改的文件?

采纳答案by Asenar

you can use the git effort(from the git-extraspackage) command which shows statistics about how many commits per files (by commits and active days).

您可以使用git effort(来自git-extras包)命令,该命令显示有关每个文件的提交次数(按提交和活动天数)的统计信息。

EDIT: git effort is justa bash script you can find hereand adapt to your needs if you need something more special.

编辑:gitwork只是一个 bash 脚本,你可以在这里找到并适应你的需求,如果你需要更特别的东西。

回答by Mark Longair

You could do something like the following:

您可以执行以下操作:

git log --pretty=format: --name-only | sort | uniq -c | sort -rg | head -10

The log just outputs the names of the files that have been changed in each commit, while the rest of it just sorts and outputs the top 10 most frequently appearing filenames.

日志只输出在每次提交中更改的文件的名称,而其余部分只是排序并输出前 10 个最常出现的文件名。

回答by Steven Penny

I noticed that both Mark'sand sehe'sanswers do not --followthe files, that is to say they stop once they reach a file rename. This script will be much slower, but will work for that purpose.

我注意到 Marksehe 的答案都不--follow是文件,也就是说,一旦到达文件重命名,它们就会停止。这个脚本会慢得多,但可以用于这个目的。

git ls-files |
while read aa
do
  printf . >&2
  set $(git log --follow --oneline "$aa" | wc)
  printf '%s\t%s\n'  "$aa"
done > bb
echo
sort -nr bb
rm bb

git-most.sh

git-most.sh

回答by Mickey Perlstein

This is a windows version

这是一个windows版本

git log --pretty=format: --name-only  > allfiles.csv

then open in excel

然后用excel打开

A1: FileName
A2: isVisibleFilename  >> =IFERROR(IF(C2>0,TRUE,FALSE),FALSE)
A3: DotLocation >> =FIND("@",SUBSTITUTE(A2,".","@",(LEN(A2)-LEN(SUBSTITUTE(A2,".","")))/LEN(".")))
A4: HasExt       >> =C2>1
A5: TYPE        >> =IF(D2=TRUE,MID(A2,C2+1,18),"")

create pivot table

创建数据透视表

values: Type
  Filter: isFilename = true
  Rows : Type
  Sub : FileName

click [Count Of TYPE] -> Sort -> Sort Largest To Smallest

回答by hyeomans

For powershell, assuming you got git bash installed

对于 powershell,假设您安装了 git bash

git log --pretty=format: --name-only | sort | uniq -c | sort -Descending | select -First 10

回答by Andy

git whatchanged --all | \grep "\.\.\." | cut -d' ' -f5- | cut -f2- | sort | uniq -c | sort

If you only want to see your files add --authorto git whatchanged --author=name --all.

如果您只想看到您的文件添加--authorgit whatchanged --author=name --all.

回答by Reginald Blue

This is probably obvious, but, the queries provided will show all files, but, perhaps you're not interested in knowing that your configuration or project files are the most updated. A simple grep will isolate to your code files, for example:

这可能是显而易见的,但是,提供的查询将显示所有文件,但是,您可能不想知道您的配置或项目文件是最新的。一个简单的 grep 将隔离到您的代码文件,例如:

git log --pretty=format: --name-only | grep .cs$ | sort | uniq -c | sort -rg | head -20

回答by Pawan Maheshwari

We can also find out files changed between two commits or branches, for e.g.

我们还可以找出两个提交或分支之间更改的文件,例如

git log  --pretty=format: --name-only <source_branch>...<target_branch> | sort | uniq -c | sort -rg | head -50 

回答by Omar Rodriguez

Old question, but I think still a very useful question. Here is a working example in straight powershell. This will get the top 10 most changed files in your repo with respect to the branch you are on.

老问题,但我认为仍然是一个非常有用的问题。这是直接 powershell 中的一个工作示例。这将获得您的存储库中与您所在的分支相关的前 10 个更改最多的文件。

git log --pretty=format: --name-only | Where-Object { ![string]::IsNullOrEmpty($_) } | Sort-Object | Group-Object  | Sort-Object -Property Count -Descending | Select-Object -Property Count, Name -First 10