2

I need to generate a list of all the files that has been changed in this year.

The following snippet does the job - but it take ~10 minutes to run:

for i in $(git ls-files)
do
    if [[ $(git log -1 --date=short --format="%ad" -- $i) =~ 2016- ]]
    then
        echo $i
    fi
done

How this be done in a more efficient way?

Harsh_Joshi
  • 47
  • 1
  • 8
Allan
  • 4,562
  • 8
  • 38
  • 59

3 Answers3

0

Based on a 90% duplicate you can simply do git diff --stat HEAD 'HEAD@{2016-01-01}.

Community
  • 1
  • 1
l0b0
  • 55,365
  • 30
  • 138
  • 223
0

This works and also lists files that were touched in any commit, and which may not exist in the current version anymore, or which may have phased in and out of existence:

git log --since=2016-01-01 --format=format:%H | \
  xargs git show --format=format: --name-only | \
  grep . | sort -u

It will be faster than the attempt you had, but it will still do much work; you will have to see if it is quick enough for your particular repository.

If you don't need the complete information (i.e., about now missing files), just do a git diff between the first commit of the year and your HEAD...

AnoE
  • 8,048
  • 1
  • 21
  • 36
0
git diff --name-only $(git rev-list -1 --first-parent --before=2016-1-1 HEAD)
jthill
  • 55,082
  • 5
  • 77
  • 137
  • I get incorrect results if I test this with branches. It will then use the merge point and not the point in time there the file is changed – Allan Jun 25 '16 at 19:03