4

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:

Community
  • 1
  • 1
Amelio Vazquez-Reina
  • 91,494
  • 132
  • 359
  • 564
  • This is going to be some very straightforward awking on something like `git log --name-only --pretty=%x0a%cD`. – jthill Jun 21 '16 at 20:24

1 Answers1

1

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

ElpieKay
  • 27,194
  • 6
  • 32
  • 53
  • Thanks @ElpieKay. Very helpful. I simplified the original problem a bit. As a matter of fact, I think it's the "simpler problem" what I realized it's most useful. – Amelio Vazquez-Reina Jun 22 '16 at 03:41