'Git: Show files which were not recently modified

In order to clean some git repo, I'd like to list all files which didn't receive any new commit for more than some period (let's tell one year for example).

I know how to list X most recently modified files, but not how to do the opposite :)

Thanks.



Solution 1:[1]

Here is a 1-liner to show the files that have not been altered in the last year:

git ls-files | grep -v "$(git log --pretty=format: --name-only --since='1 year ago' | sort | uniq)"

You could perhaps wrap this up in an alias to make it easier to invoke.

Solution 2:[2]

Write a script which loop over all your files, extract the modification date from the files and then print it.

It has nothing to do with GIt. :-)


If you want to use git command to do it you can't use the ls-tree command:

# loop over the files and print last modification date
git ls-tree -r --name-only HEAD | while read filename; do
  echo "$(git log -1 --format="%ad" -- $filename) $filename"
done

ls-tree

List the contents of a tree object
--name-only - print out only file names

The loop and print out form the log of the file the last modification date

Solution 3:[3]

To overcome the grep: Argument list too long error, one must work via files:

$ git ls-files --full-name | sort > all.git
$ git log --pretty=format: --name-only --since='1 year ago' | sort | uniq > recent.git
$ comm -23 all.git recent.git

(comm is a linux only utility, hopefully there are similar utilities for other platforms)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jonathan.Brink
Solution 2 Community
Solution 3 Ofek Shilon