How to count how many times each file has been changed in git?

I'm working on a real mess of a project and we plan to reorganize it in a few months, but we don't have time. I want to see which files are most modified because the functions / codes contained in those files will take precedence when refactoring and improving my performance.

Is it possible to get the number of times each file has been changed since the first commit or a specific week, in table format or whatever, in git? If so, how?

I apologize for not providing "what I've tried" because, to be honest, I rarely use git from the command line and I'm actually poor and the GUI is not enough.

+3


source to share


1 answer


To count the number of commits for each of your files, you could do something like this

#!/bin/bash
for file in *.php;
do
echo $file
git log --oneline -- $file | wc -l
done

      

"git log" is the key git command here.

Here are some git commands and options to look at

git log 

git log --oneline 

      

Get the change log for a specific file

git log -- filename

      



To get the changelog for a specific file for a specific date, you can do

git log --after="2017-05-09T16:36:00-07:00" --before="2017-05-10T08:00:00-07:00" -- myfile

      

You might want to try

git log --pretty=format

      

you can search all different formats

You can get a private repository on github and push the whole thing; it will be a nice graphical way to see all the changes for any of your changed files.

+1


source







All Articles