How can I list files sorted by their modification time?
I want the git modification time, not the system modification time. For example, if I have a (committed) file README
, then
touch README
will change the system modification time... but the git status would remain unchanged.
If I try
git ls-files -z | xargs -0 ls -t
this will sort by the system modification time.
Is there any option to git ls-files
that would list files sorted by their git modification time?
ls command ls – Listing contents of directory, this utility can list the files and directories and can even list all the status information about them including: date and time of modification or access, permissions, size, owner, group etc.
Git stores the last modification time for each file, based on its commit history.
The 'ls' command lists all files and folders in a directory at the command line, but by default ls returns a list in alphabetical order. With a simple command flag, you can have ls sort by date instead, showing the most recently modified items at the top of the ls command results.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With