threads / discuss / 22511

Using "git log" to find the files patched at the same time as a named file

Subject: Using "git log" to find the files patched at the same time as a named file

## tl;dr

5 messages between Feb 3, 2010 and Feb 3, 2010.

replies: 4people: 2as markdown or json

Zack Brown· Feb 3, 2010, 20:38 UTC · lore
Hi folks,

If I have a filename I'm interested in, and I want to find other files that have been modified in the same commits that modified the file I'm interested in, how could I do that with git?

If I give the command $ git log --name-only then the bottom of each log entry will list all the files that were modified by that commit. That's basically what I want, except that the command will list all log entries, not just the ones that modified the file I'm interested in.

If I give the command $ git log --name-only fs/fuse/file.c then the bottom of each log entry only lists fs/fuse/file.c, even if the very same commit showed up in the output from the previous command with multiple files in addition to that one. In other words, the "git log --name-only fs/fuse/file.c" command will only list fs/fuse/file.c as being changed, in commits that I know changed more than just that one file.

Is there a git command that will run in roughly the same amount of time as the ones given above (i.e. with only a single invocation of git), but that will only output the commits that affected the file I'm interested in, and that will also list any other files changed in those same commits?

Many thanks, Zack

-- 
Zack Brown
Junio C Hamano· Feb 3, 2010, 20:52 UTC · re: Zack Brown · lore

Re: Using "git log" to find the files patched at the same time as a named file

Zack Brown <zacharyb@gmail.com> writes:
> If I have a filename I'm interested in, and I want to find other files
> that have been modified in the same commits that modified the file I'm
> interested in, how could I do that with git?
Like this?
$ git log --full-diff --name-status v1.6.0..master -- Makefile

to ask "Which files have changed in the commit that touch Makefile since v1.6.0 up to the tip of the master?"

Zack Brown· Feb 3, 2010, 21:14 UTC · re: Junio C Hamano · lore

Re: Using "git log" to find the files patched at the same time as a named file

On Wed, Feb 3, 2010 at 3:52 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 9 quoted lines
> Zack Brown <zacharyb@gmail.com> writes:
>
>> If I have a filename I'm interested in, and I want to find other files
>> that have been modified in the same commits that modified the file I'm
>> interested in, how could I do that with git?
>
> Like this?
>
> $ git log --full-diff --name-status v1.6.0..master -- Makefile
Yes! Thank you!

I went back to the man page to see why I didn't find that before. Here's the text for the --full-diff option:

   "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."

That's all the text that deals with --full-diff in the git log manpage. I'm not sure what it's trying to say - it seems really hard to understand. What about something like this:

"Without this flag, "git log -p <path>..." shows commits that touch the specified paths, but it only includes the diffs from those commits that affected those specified paths, regardless of whether other paths were changed in those same commits. With "git log --full-diff -p <path>...", git still only reports commits that touch the specified path, but now it also includes the diffs that affected any other paths changed in those same commits."

Would that be an improvement?

Be well, Zack

>
> to ask "Which files have changed in the commit that touch Makefile since
> v1.6.0 up to the tip of the master?"
>
-- 
Zack Brown
Junio C Hamano· Feb 3, 2010, 21:36 UTC · re: Zack Brown · lore

Re: Using "git log" to find the files patched at the same time as a named file

Zack Brown <zacharyb@gmail.com> writes:
> ... What about something like this:
>
> "Without this flag, "git log -p <path>..." shows commits that touch
> the specified paths, but it only includes the diffs from those commits

I would say "s/but/and/", because it is more natural that you get the "limited" view after you explicitly stated that you are "only interested in these things" by giving pathspecs.

Show 5 quoted lines
> that affected those specified paths, regardless of whether other paths
> were changed in those same commits. With "git log --full-diff -p
> <path>...", git still only reports commits that touch the specified
> path, but now it also includes the diffs that affected any other paths
> changed in those same commits."

And "but" on the second line from the bottom makes sense---by giving the option, you are telling it to work differently.

> Would that be an improvement?

Surely. I would suspect that people would go even further. "-p" is not very special (notice I used --name-status in my example).

Also I think the description should start with what it _does_, not with what happens without it.

So how about this?
diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt
index 0e39bb6..5dd1c0c 100644
--- a/Documentation/git-log.txt
+++ b/Documentation/git-log.txt
@@ -49,11 +49,14 @@ include::diff-options.txt[]
 	commit was reached.
 
 --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.
+	Show all changes, even outside the given pathspecs.
++
+Pathspecs <path>... given to "git log [<options>] <path>..."  limit the
+output to the commits that touch the specified paths.  When options to
+show changes introduced by these commits (e.g. "-p", "--name-only") are
+given, the output of the changes are also limited to the specified paths.
+This option lifts the latter limit and tells "git log" to include all
+changes, even the ones outside of the given pathspecs.
 
 --follow::
 	Continue listing the history of a file beyond renames.
Zack Brown· Feb 3, 2010, 21:52 UTC · re: Junio C Hamano · lore

Re: Using "git log" to find the files patched at the same time as a named file

That looks much clearer. But I would change the final sentence to, "This option lifts that limit and tells "git log" to include changes from all paths that were affected by the outputted commits, not just the changes from the paths specified on the command line."

Be well, Zack

On Wed, Feb 3, 2010 at 4:36 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 57 quoted lines
> Zack Brown <zacharyb@gmail.com> writes:
>
>> ... What about something like this:
>>
>> "Without this flag, "git log -p <path>..." shows commits that touch
>> the specified paths, but it only includes the diffs from those commits
>
> I would say "s/but/and/", because it is more natural that you get the
> "limited" view after you explicitly stated that you are "only interested
> in these things" by giving pathspecs.
>
>> that affected those specified paths, regardless of whether other paths
>> were changed in those same commits. With "git log --full-diff -p
>> <path>...", git still only reports commits that touch the specified
>> path, but now it also includes the diffs that affected any other paths
>> changed in those same commits."
>
> And "but" on the second line from the bottom makes sense---by giving the
> option, you are telling it to work differently.
>
>> Would that be an improvement?
>
> Surely.  I would suspect that people would go even further.  "-p" is not
> very special (notice I used --name-status in my example).
>
> Also I think the description should start with what it _does_, not with
> what happens without it.
>
> So how about this?
>
> diff --git a/Documentation/git-log.txt b/Documentation/git-log.txt
> index 0e39bb6..5dd1c0c 100644
> --- a/Documentation/git-log.txt
> +++ b/Documentation/git-log.txt
> @@ -49,11 +49,14 @@ include::diff-options.txt[]
>        commit was reached.
>
>  --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.
> +       Show all changes, even outside the given pathspecs.
> ++
> +Pathspecs <path>... given to "git log [<options>] <path>..."  limit the
> +output to the commits that touch the specified paths.  When options to
> +show changes introduced by these commits (e.g. "-p", "--name-only") are
> +given, the output of the changes are also limited to the specified paths.
> +This option lifts the latter limit and tells "git log" to include all
> +changes, even the ones outside of the given pathspecs.
>
>  --follow::
>        Continue listing the history of a file beyond renames.
>
>
>
-- 
Zack Brown

← back to recent threads