When I use a <path>
argument with git log --stat
to limit the log to
commits modifying <path>
, git lists <path>
as the only modified file when
displaying the selected commits. I would instead like to see all modified
paths listed for each selected commit.
For example:
$ echo test > a.txt
$ echo test > b.txt
$ git add a.txt b.txt
$ git commit -m test
[...]
2 files changed, 2 insertions(+), 0 deletions(-)
[...]
$ git log -n1 --stat
[...]
a.txt | 1 +
b.txt | 1 +
2 files changed, 2 insertions(+), 0 deletions(-)
$ git log -n1 --stat -- a.txt
[...]
a.txt | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
Note that the second git log
, with the path argument a.txt
, says
"1 files changed", when in fact "2 files changed". I would like git
to tell me that both a.txt
and b.txt
changed, even though I
selected the commit based on the path a.txt
.
UPDATE: @jacknagel answered my question, but it turns out his solution doesn't work in my real use case. In my real use case, I'm looking for all commits that modified a file, including renames, in a case where two related projects diverged. I need to figure out what changes in one project imply corresponding changes (I need to make) in the other project. Unfortunately, git
complains when I try to use --full-diff
and --follow
at the same time.
So, in my real situation, I'm trying to run:
git log --stat --follow -- a.txt
and a solution that works in this case is:
git log --format='%H' --follow -- a.txt | xargs git show --stat -C
You can get this behavior using the --full-diff
option:
--full-diff
Without this flag, "git log -p <path>..." shows commits that touch
the specified paths, and diffs about the same specified paths. With
this, the full diff is shown for commits that touch the specified
paths; this means that "<path>..." limits only commits, and doesn't
limit diff for those commits.
Note that this affects all diff-based output types, e.g. those
produced by --stat etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With