{"thread":{"id":"59401","subject":"Buggy `git log -- path` behavior","startedAt":"2023-03-15T16:17:05Z","lastAt":"2023-03-17T16:47:17Z","messageCount":3,"participants":["Matthew DeVore","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"473541","messageId":"4c02cd71-8bfc-4b6e-9ec0-3d98598a695a@app.fastmail.com","threadId":"59401","inReplyTo":null,"subject":"Buggy `git log -- path` behavior","fromName":"Matthew DeVore","fromEmail":"matvore@pobox.com","sentAt":"2023-03-15T16:04:12Z","receivedAt":"2023-03-15T16:17:05Z","isPatch":false,"sender":{"key":"matvore@pobox.com","avatar":null},"body":"Hello,\n\nI think the below terminal session demonstrates a bug in git log. Notice the first git log command gives no output. Any thoughts?\n\n~/src$ git clone http://github.com/torvalds/linux\n...\n~/src$ cd linux\n~/src/linux$ git checkout v5.15\n~/src/linux$ cd Documentation/vm\n~/src/linux/Documentation/vm$ git log -n2 --name-status --oneline -- pagemap.rst\n~/src/linux/Documentation/vm$ git log -n2 --name-status --oneline -- 'pagemap.*'\n1ad1335dc586 docs/admin-guide/mm: start moving here files from Documentation/vm\nD       Documentation/vm/pagemap.rst\n41ea9dd36b6b docs/vm: pagemap: change document title\nM       Documentation/vm/pagemap.rst\n~/src/linux/Documentation/vm$\n\nThank you,\nMatthew\n"},{"id":"473545","messageId":"ZBH7Uiv7fH9UnB4v@coredump.intra.peff.net","threadId":"59401","inReplyTo":"4c02cd71-8bfc-4b6e-9ec0-3d98598a695a@app.fastmail.com","subject":"Re: Buggy `git log -- path` behavior","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2023-03-15T17:07:30Z","receivedAt":"2023-03-15T17:08:07Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Mar 15, 2023 at 11:04:12AM -0500, Matthew DeVore wrote:\n\n> I think the below terminal session demonstrates a bug in git log.\n> Notice the first git log command gives no output. Any thoughts?\n> \n> ~/src$ git clone http://github.com/torvalds/linux\n> ...\n> ~/src$ cd linux\n> ~/src/linux$ git checkout v5.15\n> ~/src/linux$ cd Documentation/vm\n> ~/src/linux/Documentation/vm$ git log -n2 --name-status --oneline -- pagemap.rst\n> ~/src/linux/Documentation/vm$ git log -n2 --name-status --oneline -- 'pagemap.*'\n> 1ad1335dc586 docs/admin-guide/mm: start moving here files from Documentation/vm\n> D       Documentation/vm/pagemap.rst\n> 41ea9dd36b6b docs/vm: pagemap: change document title\n> M       Documentation/vm/pagemap.rst\n> ~/src/linux/Documentation/vm$\n\nInteresting case. You didn't say what you think the bug is, but I assume\nyou expected that the first command should produce those two commits and\nit didn't.\n\nI think what you're seeing is the correct output, though, due to history\nsimplification. Along the first-parent history, for example,\nDocumentation/vm/pagemap.rst never existed.  And so since it does not\nexist now, we prune any side branches where it did (because they did not\nlead to the current state; the other side of the merge resolution did).\n\nTracking down the exact sequence of merges is tricky (\"git log --graph\"\nis unreadably huge here). But it looks like the file was added by\nad56b738c5dd (docs/vm: rename documentation files to .rst, 2018-03-21).\nThat was merged into docs-next via 24844fd33945 (Merge branch 'mm-rst'\ninto docs-next, 2018-04-16), which then eventually moved it in\n1ad1335dc586 (docs/admin-guide/mm: start moving here files from\nDocumentation/vm, 2018-04-18).\n\nSo any merges between history containing those commits (where the file\nis gone because it went away) and history that didn't have any of them\n(where the file never existed) are candidates for simplification, since\nthe side branch in its total effect didn't contribute to changing the\npath.\n\nIf you don't want that simplification, use --full-history (though you\nprobably also want --simplify-merges in this case).\n\nSo why does your second command produce output? It's because it matches\npagemap.txt, too. And along that side branch that created and removed\npagemap.rst, there are changes to pagemap.txt (since, after all, it was\nconverted into pagemap.rst). If you get rid of the \"-n2\", you'll see\nthose commits.\n\n-Peff\n"},{"id":"473655","messageId":"ae193764-daf2-4fff-89cf-39396f420cb3@app.fastmail.com","threadId":"59401","inReplyTo":"ZBH7Uiv7fH9UnB4v@coredump.intra.peff.net","subject":"Re: Buggy `git log -- path` behavior","fromName":"Matthew DeVore","fromEmail":"matvore@pobox.com","sentAt":"2023-03-17T16:46:26Z","receivedAt":"2023-03-17T16:47:17Z","isPatch":false,"sender":{"key":"matvore@pobox.com","avatar":null},"body":"On Wed, Mar 15, 2023, at 12:07, Jeff King wrote:\n> I think what you're seeing is the correct output, though, due to history\n> simplification. Along the first-parent history, for example,\n> Documentation/vm/pagemap.rst never existed.  And so since it does not\n> exist now, we prune any side branches where it did (because they did not\n> lead to the current state; the other side of the merge resolution did).\n> \n> Tracking down the exact sequence of merges is tricky (\"git log --graph\"\n> is unreadably huge here). But it looks like the file was added by\n> ad56b738c5dd (docs/vm: rename documentation files to .rst, 2018-03-21).\n> That was merged into docs-next via 24844fd33945 (Merge branch 'mm-rst'\n> into docs-next, 2018-04-16), which then eventually moved it in\n> 1ad1335dc586 (docs/admin-guide/mm: start moving here files from\n> Documentation/vm, 2018-04-18).\n\nThis was thought-provoking. ad56b738c5dd is a side-branch. I expected a\npath filter to find changes since git log would show this commit when\ninvoked with no other args.\n\nBut the only reason git follows the side branch in the filterless or\n'pagemap.*' case is because git sees pagemap.txt (matching the glob) in\nthe first-parent line being removed when the side branch is merged into\nthis first-parent line.\n\nAs I usually use --name-status as a default in my workflow, I was\nsurprised git log couldn't find something that grep could :)\n\nThank you for the thorough explanation despite my terse complaint.\n"}]}