Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git ls-files sort by modification time

Tags:

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?

like image 546
Vijay Murthy Avatar asked Oct 14 '13 14:10

Vijay Murthy


People also ask

Which command gives information about time of last modification does on file?

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.

Does git preserve file modification time?

Git stores the last modification time for each file, based on its commit history.

How do you sort files by date in Unix?

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.


1 Answers

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
like image 71
devnull Avatar answered Oct 07 '22 00:10

devnull