{"thread":{"id":"63954","subject":"[Bug] commit cleanup does not happen during autosquash rebase","startedAt":"2025-08-13T11:40:03Z","lastAt":"2025-09-18T15:12:58Z","messageCount":4,"participants":["Simon Cheng","Phillip Wood"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"524119","messageId":"CA+itcS3DxbgpFy2aPRvHQvTAYE=dU0kfeDdidVwWLU=rBAWR4w@mail.gmail.com","threadId":"63954","inReplyTo":null,"subject":"[Bug] commit cleanup does not happen during autosquash rebase","fromName":"Simon Cheng","fromEmail":"cyqsimon@gmail.com","sentAt":"2025-08-13T11:39:51Z","receivedAt":"2025-08-13T11:40:03Z","isPatch":false,"sender":{"key":"cyqsimon@gmail.com","avatar":null},"body":"Thank you for filling out a Git bug report!\nPlease answer the following questions to help us understand your issue.\n\nWhat did you do before the bug happened? (Steps to reproduce your issue)\n\n1. Initialize a git repo with `git init`\n2. Install a custom `prepare-commit-msg` hook that injects some comments\n  - Intention: inject the output of `git log --oneline -n10` during\ninteractive commit, so I can see past commits\n3. Run `git config commit.cleanup strip`\n  - Intention: strip the injected comments too in non-interactive mode\n(e.g. `git cherry-pick` & `git rebase`)\n4. Run `touch foo && git add -A && git commit -m \"Initial commit\"`\n5. Run `touch bar && git add -A && git commit --fixup=@`\n6. Run `git rebase --root --autosquash`\n\nWhat did you expect to happen? (Expected behavior)\n\nGit would perform the autosquash, while keeping the commit message of\nthe squash target unchanged.\n\nWhat happened instead? (Actual behavior)\n\nGit performed the autosquash, but the commit message of the squash\ntarget is now clobbered with my injected comments.\n\nWhat's different between what you expected and what actually happened?\n\nI expected commit cleanup to happen during the autosquash. It seems\nlike that didn't happen.\n\nAnything else you want to add:\n\nHere is my `prepare-commit-msg` script. But I expect this issue to be\nreplicable with anything that injects comments.\n\n```\n#!/usr/bin/env bash\n{\n  echo '# Last 10 commits:'\n  git log --oneline -n 10 --decorate=short | sed 's/^/#   /'\n  echo '#'\n} >> \"$1\"\n```\n\nPlease review the rest of the bug report below.\nYou can delete any lines you don't wish to share.\n\n\n[System Info]\ngit version:\ngit version 2.50.1\ncpu: x86_64\nbuilt from commit: d82adb61ba2fd11d8f2587fca1b6bd7925ce4044\nsizeof-long: 8\nsizeof-size_t: 8\nshell-path: /bin/sh\nlibcurl: 8.14.1\nOpenSSL: OpenSSL 3.5.1 1 Jul 2025\nzlib-ng: 2.2.4\nSHA-1: SHA1_DC\nSHA-256: SHA256_BLK\nuname: Linux 6.12.41-1-lts #1 SMP PREEMPT_DYNAMIC Fri, 01 Aug 2025\n20:42:03 +0000 x86_64\ncompiler info: gnuc: 15.1\nlibc info: glibc: 2.42\n$SHELL (typically, interactive shell): /bin/bash\n\n\n[Enabled Hooks]\nprepare-commit-msg\n"},{"id":"524347","messageId":"63e7901f-4210-438e-9389-8117d5fb83b6@gmail.com","threadId":"63954","inReplyTo":"CA+itcS3DxbgpFy2aPRvHQvTAYE=dU0kfeDdidVwWLU=rBAWR4w@mail.gmail.com","subject":"Re: [Bug] commit cleanup does not happen during autosquash rebase","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2025-08-18T15:14:00Z","receivedAt":"2025-08-18T15:14:04Z","isPatch":false,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Simon\n\nOn 13/08/2025 12:39, Simon Cheng wrote:\n> \n> What did you do before the bug happened? (Steps to reproduce your issue)\n> \n> 1. Initialize a git repo with `git init`\n> 2. Install a custom `prepare-commit-msg` hook that injects some comments\n>    - Intention: inject the output of `git log --oneline -n10` during\n> interactive commit, so I can see past commits\n> 3. Run `git config commit.cleanup strip`\n>    - Intention: strip the injected comments too in non-interactive mode\n> (e.g. `git cherry-pick` & `git rebase`)\n> 4. Run `touch foo && git add -A && git commit -m \"Initial commit\"`\n> 5. Run `touch bar && git add -A && git commit --fixup=@`\n> 6. Run `git rebase --root --autosquash`\n\nThanks for providing a simple way to reproduce this\n\n> What did you expect to happen? (Expected behavior)\n> \n> Git would perform the autosquash, while keeping the commit message of\n> the squash target unchanged.\n> \n> What happened instead? (Actual behavior)\n> \n> Git performed the autosquash, but the commit message of the squash\n> target is now clobbered with my injected comments.\n\nIt looks like this stems from f7d42ceec52 (rebase -i: do leave commit \nmessage intact in fixup! chains, 2021-01-28) which was added in response \nto a bug report[1]. That commit switched from always cleaning up the \nfixup message to never cleaning it up. I wonder if instead we should be \nrespecting the user's commit.cleanup setting. The commit message says \nthat should not respect commit.cleanup because we want to use the \nmessage verbatim but that is not what we do with \"pick\" commands which \nrespect commit.cleanup if it is set. Given that we call the \nprepare-commit-msg hook we cannot be sure that we're reusing the \noriginal commit message verbatim anyway so I think we should probably \nchange \"fixup\" commands to use the same cleanup flags as \"pick\" commands.\n\nI'm going to be off the list for a week from tomorrow but I'll try and \nlook at this again when I'm back if no one else has picked it up in the \nmeantime.\n\nThanks\n\nPhillip\n\n[1] \nhttps://lore.kernel.org/git/CANVGpwZGbzYLMeMze64e_OU9p3bjyEgzC5thmNBr6LttBt+YGw@mail.gmail.com/\n\n> What's different between what you expected and what actually happened?\n> \n> I expected commit cleanup to happen during the autosquash. It seems\n> like that didn't happen.\n> \n> Anything else you want to add:\n> \n> Here is my `prepare-commit-msg` script. But I expect this issue to be\n> replicable with anything that injects comments.\n> \n> ```\n> #!/usr/bin/env bash\n> {\n>    echo '# Last 10 commits:'\n>    git log --oneline -n 10 --decorate=short | sed 's/^/#   /'\n>    echo '#'\n> } >> \"$1\"\n> ```\n> \n> Please review the rest of the bug report below.\n> You can delete any lines you don't wish to share.\n> \n> \n> [System Info]\n> git version:\n> git version 2.50.1\n> cpu: x86_64\n> built from commit: d82adb61ba2fd11d8f2587fca1b6bd7925ce4044\n> sizeof-long: 8\n> sizeof-size_t: 8\n> shell-path: /bin/sh\n> libcurl: 8.14.1\n> OpenSSL: OpenSSL 3.5.1 1 Jul 2025\n> zlib-ng: 2.2.4\n> SHA-1: SHA1_DC\n> SHA-256: SHA256_BLK\n> uname: Linux 6.12.41-1-lts #1 SMP PREEMPT_DYNAMIC Fri, 01 Aug 2025\n> 20:42:03 +0000 x86_64\n> compiler info: gnuc: 15.1\n> libc info: glibc: 2.42\n> $SHELL (typically, interactive shell): /bin/bash\n> \n> \n> [Enabled Hooks]\n> prepare-commit-msg\n> \n\n"},{"id":"526325","messageId":"CA+itcS2Knde3K_JuVru6_s=Eh0rPBPi1aa1=y0_wyA-=A7CXsQ@mail.gmail.com","threadId":"63954","inReplyTo":"63e7901f-4210-438e-9389-8117d5fb83b6@gmail.com","subject":"Re: [Bug] commit cleanup does not happen during autosquash rebase","fromName":"Simon Cheng","fromEmail":"cyqsimon@gmail.com","sentAt":"2025-09-15T09:03:14Z","receivedAt":"2025-09-15T09:03:26Z","isPatch":false,"sender":{"key":"cyqsimon@gmail.com","avatar":null},"body":"Resending because I accidentally used HTML mode.\n\nThanks Phillip,\n\nSorry for replying so late. I forgot to set up notifications for this\nemail address, so I had basically completely forgotten about this\nmatter.\n\nYes I fully agree with your proposed approach. Also it's probably a\ngood idea to update the `git-config(1)` man page to document all the\ncommands affected by `commit.cleanup`.\n\nCheers,\n\nSimon\n\n\nOn Mon, 18 Aug 2025 at 23:14, Phillip Wood <phillip.wood123@gmail.com> wrote:\n>\n> Hi Simon\n>\n> On 13/08/2025 12:39, Simon Cheng wrote:\n> >\n> > What did you do before the bug happened? (Steps to reproduce your issue)\n> >\n> > 1. Initialize a git repo with `git init`\n> > 2. Install a custom `prepare-commit-msg` hook that injects some comments\n> >    - Intention: inject the output of `git log --oneline -n10` during\n> > interactive commit, so I can see past commits\n> > 3. Run `git config commit.cleanup strip`\n> >    - Intention: strip the injected comments too in non-interactive mode\n> > (e.g. `git cherry-pick` & `git rebase`)\n> > 4. Run `touch foo && git add -A && git commit -m \"Initial commit\"`\n> > 5. Run `touch bar && git add -A && git commit --fixup=@`\n> > 6. Run `git rebase --root --autosquash`\n>\n> Thanks for providing a simple way to reproduce this\n>\n> > What did you expect to happen? (Expected behavior)\n> >\n> > Git would perform the autosquash, while keeping the commit message of\n> > the squash target unchanged.\n> >\n> > What happened instead? (Actual behavior)\n> >\n> > Git performed the autosquash, but the commit message of the squash\n> > target is now clobbered with my injected comments.\n>\n> It looks like this stems from f7d42ceec52 (rebase -i: do leave commit\n> message intact in fixup! chains, 2021-01-28) which was added in response\n> to a bug report[1]. That commit switched from always cleaning up the\n> fixup message to never cleaning it up. I wonder if instead we should be\n> respecting the user's commit.cleanup setting. The commit message says\n> that should not respect commit.cleanup because we want to use the\n> message verbatim but that is not what we do with \"pick\" commands which\n> respect commit.cleanup if it is set. Given that we call the\n> prepare-commit-msg hook we cannot be sure that we're reusing the\n> original commit message verbatim anyway so I think we should probably\n> change \"fixup\" commands to use the same cleanup flags as \"pick\" commands.\n>\n> I'm going to be off the list for a week from tomorrow but I'll try and\n> look at this again when I'm back if no one else has picked it up in the\n> meantime.\n>\n> Thanks\n>\n> Phillip\n>\n> [1]\n> https://lore.kernel.org/git/CANVGpwZGbzYLMeMze64e_OU9p3bjyEgzC5thmNBr6LttBt+YGw@mail.gmail.com/\n>\n> > What's different between what you expected and what actually happened?\n> >\n> > I expected commit cleanup to happen during the autosquash. It seems\n> > like that didn't happen.\n> >\n> > Anything else you want to add:\n> >\n> > Here is my `prepare-commit-msg` script. But I expect this issue to be\n> > replicable with anything that injects comments.\n> >\n> > ```\n> > #!/usr/bin/env bash\n> > {\n> >    echo '# Last 10 commits:'\n> >    git log --oneline -n 10 --decorate=short | sed 's/^/#   /'\n> >    echo '#'\n> > } >> \"$1\"\n> > ```\n> >\n> > Please review the rest of the bug report below.\n> > You can delete any lines you don't wish to share.\n> >\n> >\n> > [System Info]\n> > git version:\n> > git version 2.50.1\n> > cpu: x86_64\n> > built from commit: d82adb61ba2fd11d8f2587fca1b6bd7925ce4044\n> > sizeof-long: 8\n> > sizeof-size_t: 8\n> > shell-path: /bin/sh\n> > libcurl: 8.14.1\n> > OpenSSL: OpenSSL 3.5.1 1 Jul 2025\n> > zlib-ng: 2.2.4\n> > SHA-1: SHA1_DC\n> > SHA-256: SHA256_BLK\n> > uname: Linux 6.12.41-1-lts #1 SMP PREEMPT_DYNAMIC Fri, 01 Aug 2025\n> > 20:42:03 +0000 x86_64\n> > compiler info: gnuc: 15.1\n> > libc info: glibc: 2.42\n> > $SHELL (typically, interactive shell): /bin/bash\n> >\n> >\n> > [Enabled Hooks]\n> > prepare-commit-msg\n> >\n>\n"},{"id":"526704","messageId":"ff67849a-74d5-4a3a-bfee-de261aa66ca3@gmail.com","threadId":"63954","inReplyTo":"CA+itcS2Knde3K_JuVru6_s=Eh0rPBPi1aa1=y0_wyA-=A7CXsQ@mail.gmail.com","subject":"Re: [Bug] commit cleanup does not happen during autosquash rebase","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2025-09-18T15:12:55Z","receivedAt":"2025-09-18T15:12:58Z","isPatch":false,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 15/09/2025 10:03, Simon Cheng wrote:\n> Resending because I accidentally used HTML mode.\n> \n> Thanks Phillip,\n> \n> Sorry for replying so late. I forgot to set up notifications for this\n> email address, so I had basically completely forgotten about this\n> matter.\n\nYou're reply turned out to be timely as I was thinking about this bug \njust before I read it on Monday. I've sent a patch which you should be \nCc'd on. For anyone following the discussion on the list it is available \nat \nhttps://lore.kernel.org/git/cover.1758186038.git.phillip.wood@dunelm.org.uk/\n\n> Yes I fully agree with your proposed approach. Also it's probably a\n> good idea to update the `git-config(1)` man page to document all the\n> commands affected by `commit.cleanup`.\n\nThat's a good idea but it will mean a little bit of work to audit how \ncommands are affected by that config setting.\n\nThanks\n\nPhillip\n\n> Cheers,\n> \n> Simon\n> \n> \n> On Mon, 18 Aug 2025 at 23:14, Phillip Wood <phillip.wood123@gmail.com> wrote:\n>>\n>> Hi Simon\n>>\n>> On 13/08/2025 12:39, Simon Cheng wrote:\n>>>\n>>> What did you do before the bug happened? (Steps to reproduce your issue)\n>>>\n>>> 1. Initialize a git repo with `git init`\n>>> 2. Install a custom `prepare-commit-msg` hook that injects some comments\n>>>     - Intention: inject the output of `git log --oneline -n10` during\n>>> interactive commit, so I can see past commits\n>>> 3. Run `git config commit.cleanup strip`\n>>>     - Intention: strip the injected comments too in non-interactive mode\n>>> (e.g. `git cherry-pick` & `git rebase`)\n>>> 4. Run `touch foo && git add -A && git commit -m \"Initial commit\"`\n>>> 5. Run `touch bar && git add -A && git commit --fixup=@`\n>>> 6. Run `git rebase --root --autosquash`\n>>\n>> Thanks for providing a simple way to reproduce this\n>>\n>>> What did you expect to happen? (Expected behavior)\n>>>\n>>> Git would perform the autosquash, while keeping the commit message of\n>>> the squash target unchanged.\n>>>\n>>> What happened instead? (Actual behavior)\n>>>\n>>> Git performed the autosquash, but the commit message of the squash\n>>> target is now clobbered with my injected comments.\n>>\n>> It looks like this stems from f7d42ceec52 (rebase -i: do leave commit\n>> message intact in fixup! chains, 2021-01-28) which was added in response\n>> to a bug report[1]. That commit switched from always cleaning up the\n>> fixup message to never cleaning it up. I wonder if instead we should be\n>> respecting the user's commit.cleanup setting. The commit message says\n>> that should not respect commit.cleanup because we want to use the\n>> message verbatim but that is not what we do with \"pick\" commands which\n>> respect commit.cleanup if it is set. Given that we call the\n>> prepare-commit-msg hook we cannot be sure that we're reusing the\n>> original commit message verbatim anyway so I think we should probably\n>> change \"fixup\" commands to use the same cleanup flags as \"pick\" commands.\n>>\n>> I'm going to be off the list for a week from tomorrow but I'll try and\n>> look at this again when I'm back if no one else has picked it up in the\n>> meantime.\n>>\n>> Thanks\n>>\n>> Phillip\n>>\n>> [1]\n>> https://lore.kernel.org/git/CANVGpwZGbzYLMeMze64e_OU9p3bjyEgzC5thmNBr6LttBt+YGw@mail.gmail.com/\n>>\n>>> What's different between what you expected and what actually happened?\n>>>\n>>> I expected commit cleanup to happen during the autosquash. It seems\n>>> like that didn't happen.\n>>>\n>>> Anything else you want to add:\n>>>\n>>> Here is my `prepare-commit-msg` script. But I expect this issue to be\n>>> replicable with anything that injects comments.\n>>>\n>>> ```\n>>> #!/usr/bin/env bash\n>>> {\n>>>     echo '# Last 10 commits:'\n>>>     git log --oneline -n 10 --decorate=short | sed 's/^/#   /'\n>>>     echo '#'\n>>> } >> \"$1\"\n>>> ```\n>>>\n>>> Please review the rest of the bug report below.\n>>> You can delete any lines you don't wish to share.\n>>>\n>>>\n>>> [System Info]\n>>> git version:\n>>> git version 2.50.1\n>>> cpu: x86_64\n>>> built from commit: d82adb61ba2fd11d8f2587fca1b6bd7925ce4044\n>>> sizeof-long: 8\n>>> sizeof-size_t: 8\n>>> shell-path: /bin/sh\n>>> libcurl: 8.14.1\n>>> OpenSSL: OpenSSL 3.5.1 1 Jul 2025\n>>> zlib-ng: 2.2.4\n>>> SHA-1: SHA1_DC\n>>> SHA-256: SHA256_BLK\n>>> uname: Linux 6.12.41-1-lts #1 SMP PREEMPT_DYNAMIC Fri, 01 Aug 2025\n>>> 20:42:03 +0000 x86_64\n>>> compiler info: gnuc: 15.1\n>>> libc info: glibc: 2.42\n>>> $SHELL (typically, interactive shell): /bin/bash\n>>>\n>>>\n>>> [Enabled Hooks]\n>>> prepare-commit-msg\n>>>\n>>\n\n"}]}