git ls-files sort by modification time

Best answer is by Mikko Rantalainen on serverfault:

git ls-tree -r --name-only HEAD -z | TZ=UTC xargs -0n1 -I_ git --no-pager log -1 --date=iso-local --format="%ad _" -- _ | sort 

Is there any option to git ls-files that would list files sorted by their git modification time?

I don't think so. One possible way would be to iterate over the files, get the timestamp using git log, and sort the output.

The following might work for you:

while read file; do echo $(git log --pretty=format:%ad -n 1 --date=raw -- $file) $file; done < <(git ls-tree -r --name-only HEAD) | sort -k1,1n

Tags:

Sorting

Git