Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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?

I apologize that I do not provide a "what have I tried" because frankly I rarely use git from command line and I'm really poor at it and the GUI ones are just not enough.

like image 456
Nima G Avatar asked May 10 '17 10:05

Nima G


People also ask

Does git store file modification time?

Short answer is no: they'll see the file creation date on their disk, i.e. the timestamp when the files where created for the first time on that disk.

How do you find a list of files that have been changed in a particular commit?

Find what file changed in a commit To find out which files changed in a given commit, use the git log --raw command. It's the fastest and simplest way to get insight into which files a commit affects.

What is git count?

DESCRIPTION. This counts the number of unpacked object files and disk space consumed by them, to help you decide when it is a good time to repack.


1 Answers

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.

like image 108
Ken Johnson Avatar answered Sep 29 '22 15:09

Ken Johnson