Martin's Tex-Blog

Posts on programming and generally technical topics

gitstats filter files

leave a comment »


Currently gitstats does not allow to filter files by extensions, and the only way is as author suggests:

https://github.com/dcramer/gitstats/blob/master/doc/gitstats.pod
Q: I have files in my git repository that I would like to exclude from the statistics, how do I do that?
A: At the moment the only way is to use git-filter-branch(1) to create a temporary repository and generate the statistics from that.

below is a short script on how to prepeare your repository for such filtered gitstats statistics calcualtion:

i assume you have copied your repository to some temporary folder, actually all below changes can be reverted but to be safe do it in temporary dir.

# clear file list to be removed from statistics calculation
$ rm ~/temp_gitstats_filter.txt

# get latest changes
$ git pull

# create a list of files excluding the ones ending with java and xml, those files will not be processed by gitstats
$ for i in `git ls-files | grep -Ev ‘^.*.(java|xml)$’`; do echo “$i” >> ~/temp_gitstats_filter.txt; done

# remove all the files from previously created list in current repository
$ git filter-branch -f –tree-filter ‘cat ~/temp_gitstats_filter.txt | xargs rm -f’ HEAD

# now execute your gitstats command (should be fixed for your needs)
$ gitstats .git /var/www/html/git_stats

# reset all the changes filter-branch have done
$ git reset –hard refs/original/refs/heads/master

some usefull links:
http://ktln2.org/blog/post/remove-files-from-history-with-filter-branch/
http://git.661346.n2.nabble.com/Remove-all-files-except-a-few-files-using-filter-branch-td7567155.html
http://stackoverflow.com/questions/4228100/git-i-want-to-unstage-all-files-matching-a-certain-pattern
http://unix.stackexchange.com/questions/37313/how-do-i-grep-for-multiple-patterns

Advertisement

Written by Marcin

October 13, 2014 at 9:41 am

Posted in git

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: