This does not use git log
, but if you're willing to use commit objects (hashes, branch references or other commitish identifiers), git diff
makes it simple. Example for getting the changed files for the last three commits.
$ git diff HEAD~3 --name-only
> some/path/with/file.php
> another/path/and/file.html
> yet/another.json
You can replace HEAD~3
with either a single commitish so you're comparing to the current HEAD (the commit you're "on"), or then define a commit range with <commitish>..<commitish>
:
$ git diff HEAD..abcd1234 --name-only
> file/name/here.cpp
$ git diff 1234abcd..abcd1234 --name-only
> some/file/name-here.txt
If you need to filter the files according to the modification type (e.g. added, modified, deleted...), you can use the --diff-filter
option. man git diff
:
--diff-filter=[(A|C|D|M|R|T|U|X|B)...[*]]
Select only files that are Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), have their type (i.e. regular file, symlink, submodule, ...) changed (T), are
Unmerged (U), are Unknown (X), or have had their pairing Broken (B). Any combination of the filter characters (including none) can be used. When * (All-or-none) is added
to the combination, all paths are selected if there is any file that matches other criteria in the comparison; if there is no file that matches other criteria, nothing
is selected.
If you need to use dates for filtering, then this may not be the best option. Perhaps use git log --since=...
to get the first hash for the date and pass it to git diff
?