Finding most changed files in Git

GitShell

Git Problem Overview


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

Git Solutions


Solution 1 - Git

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.

Solution 2 - Git

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

EDIT: git effort is just a bash script you can find here and adapt to your needs if you need something more special.

Solution 3 - Git

I noticed that both Mark’s and sehe’s answers do not --follow the 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.

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

Solution 4 - Git

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.

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

Solution 5 - Git

This is a windows version

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

then open in 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

Solution 6 - Git

For powershell, assuming you got git bash installed

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

Solution 7 - Git

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

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

Solution 8 - Git

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 

Solution 9 - Git

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:

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSebastianView Question on Stackoverflow
Solution 1 - GitMark LongairView Answer on Stackoverflow
Solution 2 - GitAsenarView Answer on Stackoverflow
Solution 3 - GitZomboView Answer on Stackoverflow
Solution 4 - GitOmar RodriguezView Answer on Stackoverflow
Solution 5 - GitMickey PerlsteinView Answer on Stackoverflow
Solution 6 - GithyeomansView Answer on Stackoverflow
Solution 7 - GitAndrewView Answer on Stackoverflow
Solution 8 - GitPawan MaheshwariView Answer on Stackoverflow
Solution 9 - GitReginald BlueView Answer on Stackoverflow