{"thread":{"id":"50035","subject":"Bug: `git commit --fixup` with duplicate commit messages","startedAt":"2018-12-14T12:30:50Z","lastAt":"2018-12-14T16:34:09Z","messageCount":4,"participants":["Oliver Joseph Ash","Johannes Schindelin","Rafael Ascensão","John Passaro"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"365347","messageId":"CADBHO9E7Bzk9C5ciC416S+5-cS2ANA9d+CzSjKSG+HyxwrU+2w@mail.gmail.com","threadId":"50035","inReplyTo":null,"subject":"Bug: `git commit --fixup` with duplicate commit messages","fromName":"Oliver Joseph Ash","fromEmail":"oliverjash@gmail.com","sentAt":"2018-12-14T12:30:28Z","receivedAt":"2018-12-14T12:30:50Z","isPatch":false,"sender":{"key":"oliverjash@gmail.com","avatar":"https://gravatar.com/avatar/1266c37ce2a44f50b57deef71172fc89b87db179a0d5448b7c019af6f75eb21d?d=mp&s=160"},"body":"Hi,\n\nI believe I have found a bug in `git commit --fixup`.\n\nSteps to reproduce:\n1. Create a git history with two commits (A and B) with the same\ncommit message (e.g. foo)\n2. Create a new commit using `git commit --fixup {SHA}`, referring to\nthe last commit SHA\n3. Run an interactive rebase\n\nExpected: the fixup commit should appear below the last commit in the todo list.\n\nActual: the fixup commit appears below the first commit in the todo list.\n\nIt seems that the fixup commit is moved below the most recent commit\nwith a matching commit message, however in this case there are\nduplicate commit messages. I would expect the fixup commit to be moved\nbelow the commit SHA I specified when I ran `git commit --fixup`.\n\nThanks,\nOlly\n"},{"id":"365353","messageId":"nycvar.QRO.7.76.6.1812141438340.43@tvgsbejvaqbjf.bet","threadId":"50035","inReplyTo":"CADBHO9E7Bzk9C5ciC416S+5-cS2ANA9d+CzSjKSG+HyxwrU+2w@mail.gmail.com","subject":"Re: Bug: `git commit --fixup` with duplicate commit messages","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2018-12-14T13:39:40Z","receivedAt":"2018-12-14T13:39:59Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Oliver,\n\nOn Fri, 14 Dec 2018, Oliver Joseph Ash wrote:\n\n> I believe I have found a bug in `git commit --fixup`.\n> \n> Steps to reproduce:\n> 1. Create a git history with two commits (A and B) with the same\n> commit message (e.g. foo)\n> 2. Create a new commit using `git commit --fixup {SHA}`, referring to\n> the last commit SHA\n> 3. Run an interactive rebase\n> \n> Expected: the fixup commit should appear below the last commit in the todo list.\n> \n> Actual: the fixup commit appears below the first commit in the todo list.\n> \n> It seems that the fixup commit is moved below the most recent commit\n> with a matching commit message, however in this case there are\n> duplicate commit messages. I would expect the fixup commit to be moved\n> below the commit SHA I specified when I ran `git commit --fixup`.\n\nYes, this is a problem of the design of this feature. It was done\npartially, I believe, to survive multiple rebases *without* --autosquash\nbefore a final rebase *with* --autosquash.\n\nThe behavior really is by design.\n\nCiao,\nJohannes\n"},{"id":"365354","messageId":"20181214135818.7ta7y5feumzau4g3@rigel","threadId":"50035","inReplyTo":"CADBHO9E7Bzk9C5ciC416S+5-cS2ANA9d+CzSjKSG+HyxwrU+2w@mail.gmail.com","subject":"Re: Bug: `git commit --fixup` with duplicate commit messages","fromName":"Rafael Ascensão","fromEmail":"rafa.almas@gmail.com","sentAt":"2018-12-14T14:00:03Z","receivedAt":"2018-12-14T14:00:11Z","isPatch":false,"sender":{"key":"rafa.almas@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1923789?v=4"},"body":"On Fri, Dec 14, 2018 at 12:30:28PM +0000, Oliver Joseph Ash wrote:\n> I believe I have found a bug in `git commit --fixup`.\n\nThat's not a bug, it's actually the documented behaviour of rebase\n--autosquash.\n\nAs you figured out, the squash/fixup is based on whether the message\nhas the squash!/fixup! prefix and the subject matches. But it also\nallows specifying hashes.\n\nSo for fixups, you can be explicit and use: git commit -m 'fixup! SHA'.\n\nSimilarly for squashes. (But a little less friendly as you'll need to\ndeal with passing an argument to -m that contains newlines).\n\nBut adding 'squash! SHA' when the editor opens should also work.\n\nI believe the main reason this works based on subject message matching\nis to be more friendly with scenarios where you're sharing series of\ncommits that include fixups and squashes. (Either via format patch, or\nby rebasing the series on a newer base without --autosquash).\n\nOn such cases the commit you're trying to fixup will have a different\nOID, so any hardcoded OID will be useless while commit message matching\nworks most of the time.\n\nOne potential improvement to this is to teach --fixup and --squash to\nalso add trailers like: \"{fixup,squash}: SHA\" or \"target: SHA\" and teach\n--autosquash to respect it when possible.\n\nThoughts?\n"},{"id":"365356","messageId":"CAJdN7Khgzjtzkzau4L771cvvT9D8FB4Fa43Vq_opaPxSKkXfuw@mail.gmail.com","threadId":"50035","inReplyTo":"20181214135818.7ta7y5feumzau4g3@rigel","subject":"Re: Bug: `git commit --fixup` with duplicate commit messages","fromName":"John Passaro","fromEmail":"john.a.passaro@gmail.com","sentAt":"2018-12-14T16:33:28Z","receivedAt":"2018-12-14T16:34:09Z","isPatch":false,"sender":{"key":"john.a.passaro@gmail.com","avatar":"https://avatars.githubusercontent.com/u/6754005?v=4"},"body":"On Fri, 14 Dec 2018, Oliver Joseph Ash wrote:\n\n> I believe I have found a bug in `git commit --fixup`.\n>\n> Steps to reproduce:\n> 1. Create a git history with two commits (A and B) with the same\n> commit message (e.g. foo)\n\n> 2. Create a new commit using `git commit --fixup {SHA}`, referring to\n> the last commit SHA\n> 3. Run an interactive rebase\n>\n> Expected: the fixup commit should appear below the last commit in the todo list.\n\nPerhaps another useful behavior, when the ambiguity exists (i.e. absent\nthe trailer Rafael suggested), would be to keep the existing behavior\nbut notify the user, and point to a new section in the docs on the\nsubject:\n\n\npick aaaa foo\nfixup dddd fixup! foo\npick bbbb foo\n# ambiguous autosquash: dddd may have targeted bbbb instead of aaaa.\npick cccc unrelated\n\n# Rebase 0000..dddd onto 0000 (4 commands)\n# This rebase includes one or more ambiguous autosquashes.\n# See git help rebase for more information (under AMBIGUOUS AUTOSQUASH)\n#\n# Commands:\n# (etc)\n\nOn Fri, Dec 14, 2018 at 9:00 AM Rafael Ascensão <rafa.almas@gmail.com> wrote:\n>\n> On Fri, Dec 14, 2018 at 12:30:28PM +0000, Oliver Joseph Ash wrote:\n> > I believe I have found a bug in `git commit --fixup`.\n>\n> That's not a bug, it's actually the documented behaviour of rebase\n> --autosquash.\n>\n> As you figured out, the squash/fixup is based on whether the message\n> has the squash!/fixup! prefix and the subject matches. But it also\n> allows specifying hashes.\n>\n> So for fixups, you can be explicit and use: git commit -m 'fixup! SHA'.\n>\n> Similarly for squashes. (But a little less friendly as you'll need to\n> deal with passing an argument to -m that contains newlines).\n>\n> But adding 'squash! SHA' when the editor opens should also work.\n>\n> I believe the main reason this works based on subject message matching\n> is to be more friendly with scenarios where you're sharing series of\n> commits that include fixups and squashes. (Either via format patch, or\n> by rebasing the series on a newer base without --autosquash).\n>\n> On such cases the commit you're trying to fixup will have a different\n> OID, so any hardcoded OID will be useless while commit message matching\n> works most of the time.\n>\n> One potential improvement to this is to teach --fixup and --squash to\n> also add trailers like: \"{fixup,squash}: SHA\" or \"target: SHA\" and teach\n> --autosquash to respect it when possible.\n>\n> Thoughts?\n\nI like very much the proposal to use trailers to indicate the intended target.\n\"target: SHA\" would probably be better. It could be used for a first pass and\nif no match is found (in case of rebase or patch-by-mail) or the trailer is not\npresent, fall back to the default approach of matching by subject line and\nnoting other potential matches as described above).\n"}]}