I would like to list the last commit date for a large number of files in a git repository.
For the sake of concreteness, let us assume that I want to get the last commit dates of all *.txt
files inside a particular subdirectory. There are tens of thousands of files in the repository in total, and the number of relevant *.txt
files is in the ballpark of several hundreds. There are already thousands of commits in the repository.
I tried three different approaches.
Solution 1. This question gives one answer, based on git log
. However, if I try to do something like this, it is very slow:
find . -name '*.txt' |
xargs -n1 git log --format=format:%ai -n1 --all -- '{}'
In my test case, it took several minutes – far too slow for my purposes.
Solution 2. Something like this would be much faster, less than one second:
git log --format=format:%ai --name-only .
However, then I would have to write a script that post-processes the output. Moreover, the above command prints out lots of information that is never needed: irrelevant files and old commits.
Solution 3. I also tried something like this, in order to get rid of the irrelevant files:
git log --format=format:%ai --name-only `find . -name '*.txt'`
However, this turned out to be slower than solution 2. (There was a factor 3 difference in the running time.) Moreover, it still prints old commits that are no longer needed.
Question. Am I missing something? Is there a fast and convenient approach? Preferably something that works not only right now but also in future, when we have a much larger number of commits?