I'm trying to see what opportunities I might have to refactor some code.
So I'm looking to see how to search my repository for the longest files to consider.
But how can you use git ls-files
's to return back just a certain filename
like java-files *.java
?
I'm not understanding the documentation yet. And, I could use some rephrasing to understand this.
I've tried running variations of --format='*.java'
, --format=objecttype *.java
*.java
, grep java
, and others. I have the rest of the code git ls-files | grep java | xargs ls -l | sort -nrk5 | head -n 10
from "How can I find the N largest files in a Git repository?" SO Q&A.
This seems to work just fine.
git ls-files | grep ".*java" | xargs ls -alh | sort -rhk5 | head -n 10
I've replaced instances of
-n
with-h
which gives you the filesize in a nice human-readable format.I noticed that if you're searching for smaller patterns like for
.c
files, replace".*c"
with".*\.c"
for more precision. Otherwise, I got results having entries like "doc/Guidebook.txt" because of the 'c' occurrence.