Re: Buggy `git log -- path` behavior

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Mar 15, 2023 at 11:04:12AM -0500, Matthew DeVore wrote:

> I think the below terminal session demonstrates a bug in git log.
> Notice the first git log command gives no output. Any thoughts?
> 
> ~/src$ git clone http://github.com/torvalds/linux
> ...
> ~/src$ cd linux
> ~/src/linux$ git checkout v5.15
> ~/src/linux$ cd Documentation/vm
> ~/src/linux/Documentation/vm$ git log -n2 --name-status --oneline -- pagemap.rst
> ~/src/linux/Documentation/vm$ git log -n2 --name-status --oneline -- 'pagemap.*'
> 1ad1335dc586 docs/admin-guide/mm: start moving here files from Documentation/vm
> D       Documentation/vm/pagemap.rst
> 41ea9dd36b6b docs/vm: pagemap: change document title
> M       Documentation/vm/pagemap.rst
> ~/src/linux/Documentation/vm$

Interesting case. You didn't say what you think the bug is, but I assume
you expected that the first command should produce those two commits and
it didn't.

I think what you're seeing is the correct output, though, due to history
simplification. Along the first-parent history, for example,
Documentation/vm/pagemap.rst never existed.  And so since it does not
exist now, we prune any side branches where it did (because they did not
lead to the current state; the other side of the merge resolution did).

Tracking down the exact sequence of merges is tricky ("git log --graph"
is unreadably huge here). But it looks like the file was added by
ad56b738c5dd (docs/vm: rename documentation files to .rst, 2018-03-21).
That was merged into docs-next via 24844fd33945 (Merge branch 'mm-rst'
into docs-next, 2018-04-16), which then eventually moved it in
1ad1335dc586 (docs/admin-guide/mm: start moving here files from
Documentation/vm, 2018-04-18).

So any merges between history containing those commits (where the file
is gone because it went away) and history that didn't have any of them
(where the file never existed) are candidates for simplification, since
the side branch in its total effect didn't contribute to changing the
path.

If you don't want that simplification, use --full-history (though you
probably also want --simplify-merges in this case).

So why does your second command produce output? It's because it matches
pagemap.txt, too. And along that side branch that created and removed
pagemap.rst, there are changes to pagemap.txt (since, after all, it was
converted into pagemap.rst). If you get rid of the "-n2", you'll see
those commits.

-Peff



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux