Edgar
Edgar

Reputation: 39

How to get all commit ID's after certain date and display only the files that were changed?

I need to get names of all files changed after certain date. Seems like if I have commit_id I can use
git show --name-only <commit_id>
This gives me :

commit sfffwefwew3134343(origin/<branch_name>)
Author: ...............
Date: ..................
      <Commit Msg>
abc/xyz/abc.sql

So basically two questions:
Is there a way to get just the file like abc/xyz/abc.sql?
If so, how can I get all commit id's after certain date so that I can iterate over all the id and grab the files changed?

OR

Is there a better way to find files that was changed after certain date?

Upvotes: 3

Views: 491

Answers (3)

phd
phd

Reputation: 94397

Use git diff --name-only using date as the revision. Like this:

git diff --name-only "HEAD@{2020-01-01}"

Upvotes: 1

Enrico Campidoglio
Enrico Campidoglio

Reputation: 59885

This command will give you the output you're looking for:

git log --format="%+H" --name-only --since=<date>

For example:

bcc1f17f6d6d3b8f5d55364aef5852902428afc6

dir/foo.txt
dir/bar.txt

473b9ffd0f7dade2fa896081b0a75ee1c122a4f4

dir/baz.txt

44db7a7e2cb8243ccba4621f0df9e08669513a89

dir/subdir/fiz.txt
dir/faz.txt

If you prefer to see the abbreviated commit ID, you can substitute %+H with %+h:

git log --format="%+h" --name-only --since=<date>

There's a lot you can do to format the output of git log. I recommend reading up on the different placeholders that you can use with the --format option in the documentation.

Upvotes: 2

Romain Valeri
Romain Valeri

Reputation: 21908

For a start, try

git log --pretty=format:"" --name-only --since=<date>

...which will produce an output like this, each commit producing its own files list separated by an empty line

file1.txt
file2.txt

file2.txt
dir/file3.txt
file9.txt

file1.txt

...which you can (if needed?) regroup by sending the result of the command through | sort -u to get

dir/file3.txt
file1.txt
file2.txt
file9.txt

Notes
--pretty=format:"" is here to turn off each commit's info (other than file names)
and the doc for --since is here.

Upvotes: 2

Related Questions