Nima
Nima

Reputation: 6573

How to count how many times each file was modified in git?

I am working on a real mess of a project and we've been planning to refactor it for months but nobody has the time. I want to see which files are most modified because the features/codes contained in those files will have the priority on refactoring and increasing my productivity.

Is it possible to get number of times each file was modified since first commit or a specific week, in a table format or something, in git? If so, how?

Upvotes: 7

Views: 3250

Answers (1)

Ken Johnson
Ken Johnson

Reputation: 425

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 

To get a log of changes for a specific file

git log -- filename

To get a log of changes for a specific file during 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 may want to try

git log --pretty=format

you can look up all the different formats

You could get a private repository on github and push it all up there; that would be a nice graphical way to see all the changes for any of your changed files.

Upvotes: 5

Related Questions