How to make `git log --stat - <path>` show * all * files in selected commits?

When I use the <path> argument with git log --stat to restrict the git log --stat <path> , git lists the <path> as the only modified file when displaying the selected commits. I would like to see all the modified paths listed for each selected commit.

For instance:

 $ 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 a.txt argument, says β€œ1 file changed” when in fact β€œ2 files changed”. I would like git to tell me that both a.txt and b.txt have changed, although I chose to commit based on the a.txt path.

UPDATE: @jacknagel answered my question, but it turned out that his solution does not work in my real use case. In my actual use case, I am looking for all the commits that modified the file, including renaming, in the case where two related projects diverged. I need to find out what changes in one project involve corresponding changes (I have to make) in another project. Unfortunately, git complains when I try to use --full-diff and --follow at the same time.

So, in my real situation, I am trying to run:

 git log --stat --follow -- a.txt 

and a solution that works in this case:

 git log --format='%H' --follow -- a.txt | xargs git show --stat -C 
+6
source share
3 answers

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, eg those produced by --stat etc. 
+9
source

First find the commit identifiers, then pass them to xargs (or gnu parallel ) to pass each git show identifier.

 git log --format='%H' --follow -- a.txt | xargs git show --stat -C 

On windows with powershell, something like this should work (but I haven't tested it yet.):

 git log --format='%H' --follow -- a.txt | ForEach-Object { git show --stat -C $_ } 
0
source

How do you expect the team to behave differently than it is intended? When you give a file name, you tell git to get information about this file. If you want it to display both files, use the command

 git log -n1 --stat . 

or

 git log -n1 --stat a.txt b.txt 
-1
source

Source: https://habr.com/ru/post/916413/


All Articles