filaton
filaton

Reputation: 2326

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.

Upvotes: 3

Views: 166

Answers (3)

Ofek Shilon
Ofek Shilon

Reputation: 16207

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)

Upvotes: 0

Jonathan.Brink
Jonathan.Brink

Reputation: 25433

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.

Upvotes: 2

CodeWizard
CodeWizard

Reputation: 142542

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

Upvotes: 0

Related Questions