Amelio Vazquez-Reina Amelio Vazquez-Reina - 7 months ago 34
Bash Question

List of files sorted by their most recent modification date (git) in human readable format

Say we are in a git repo with several folders and files. I am hoping to get a list of all files in the repo and their most recent modification timestamp in human readable format.

The list should be sorted by this modification timestamp.

Any ideas on how to approach this?

I am assuming

git ls-files
could be used for this but haven't found a good way to solve his problem yet.

Simpler problem:

Say we want to do the same only for the files that are currently reachable on the current branch under a given directory within the repository.

Some related threads and close solutions:


The demand to list all the files in the repo is ambitious. All the files reachable from all the refs or just from HEAD or just from one or more specific branches? To simplify it, I assume it's HEAD.

git log HEAD --pretty="/invert:%h" --name-only | grep -v -E "^\/invert:|^$" | sort -u | while read path;do echo $(git log -1 --pretty="%ad %h" --date=format:"%Y-%m-%d %H:%M:%S" -- "$path") $path;done | sort -u

%ad is author date. If you need commit date, use %cd. HEAD could be another branch or ref or a revision range.

If it's all the refs, try

git rev-list --all | xargs -i git log -1 {} --name-only --pretty="/invert:%h" | grep -v -E "^\/invert:|^$" | sort -u | while read path;do echo $(git log -1 --pretty="%ad %h" --date=format:"%Y-%m-%d %H:%M:%S" -- "$path") $path;done | sort -u

If it's all the branches, try git rev-list --branches. If it's some specific branches, git rev-list --branches=<pattern>

Updated: another way to get the changed files, git diff <commit>^ <commit> --name-only