Do you have a junky project with lots of commented out code? Git can help you find the files with the biggest damage:
git grep -c '^\s*//' | sort -n -t: -k2 -r | head
git grepis exactly like
grep, but instead of searching in the filesystem, it searches in the repository. It's faster than
grep -r .
- The pattern we're looking for is lines that start with some (or no) whitespace followed by
//. In other words, lines that contain only comment, nothing else
- The output of
git grep -cis like
grep -c, a list of filenames, with the count of matches separated by a
- To sort the output by the counts, use
-nto sort numerically, with
:as the column separator, and the second column as the key
- The sort is ascending by default, so reverse it and get the head only = first 10 records, descending order by count of matches
The solution is not perfect. For example block comments like
/* .... */ are not included. But it's better than nothing, and can help finding and cleaning up obsolete code in your projects. Or you can find other inventive uses for git grep.