3

I have a large git repository and I would like to find the list of files that were not modified for the long time sorted by date, I tried the command:

git log --pretty=format: --summary --before="<date>" 

It gives me the list of files modified files before date, but I would like to know all files sorted by date of last modification in descending order (the oldest files will be on top). Also the list should have only files currently present in the repository, I don't care about already deleted files.

Can anyone suggest the right command?

erkfel
  • 1,588
  • 2
  • 17
  • 29
  • 1
    i don't imagine git log would do this on its own... you'll likely have to pipe the results to something like `sort` - does this answer help? http://stackoverflow.com/a/19362660/251983 – Fred Jul 20 '16 at 01:16
  • @Fred thanks, will check this suggestion – erkfel Jul 20 '16 at 05:42

2 Answers2

4

Based on link, which posted @Fred in comment, you can try this:

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

It's worked for me.

Jan Marek
  • 10,390
  • 3
  • 21
  • 19
  • My tweak of this, listing the 20 least-recently-updated files, ignoring whitespace changes and renames: `while read file; do echo $(git log --pretty=format:%ai -n 1 --date=raw -w --follow -- $file) $file; done < <(git ls-tree -r --name-only HEAD) | sort | head -n 20` – Aidan Feldman Sep 25 '20 at 14:04
1

Don't think there is a git command can do this but try tree command and sort. It looks bit ugly but I believe it is very close to what you want

tree -ifFCD --timefmt '%Y%m%d %H%M%S' | sort -k1 -k2

-D print the date of the last modification time or if -c is used, the last status change time for the file listed.

Ask and Learn
  • 8,661
  • 8
  • 37
  • 43
  • 1
    Good command, thanks, but my repository is just cloned and the modification date is almost the same for all files. I tried with both -D and -c. – erkfel Jul 20 '16 at 05:22
  • I will submit a feature request to `git` maybe this will be available in future. – Ask and Learn Jul 20 '16 at 05:58