{"thread":{"id":"58089","subject":"Non-interactively rewording commit messages","startedAt":"2022-06-30T15:28:05Z","lastAt":"2022-07-01T18:18:44Z","messageCount":11,"participants":["Konstantin Ryabitsev","Carlo Marcelo Arenas Belón","Christian Couder","Ævar Arnfjörð Bjarmason","brian m. carlson","Junio C Hamano","Elijah Newren","Johannes Schindelin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"458195","messageId":"20220630152757.yxwhijvj5xoosrws@meerkat.local","threadId":"58089","inReplyTo":null,"subject":"Non-interactively rewording commit messages","fromName":"Konstantin Ryabitsev","fromEmail":"konstantin@linuxfoundation.org","sentAt":"2022-06-30T15:27:57Z","receivedAt":"2022-06-30T15:28:05Z","isPatch":false,"sender":{"key":"konstantin@linuxfoundation.org","avatar":"https://gravatar.com/avatar/7cb8827c6de56e1bd2dea16508c6708aa43feed3bf3813bcdacecdf96ceadd79?d=mp&s=160"},"body":"Hello, all:\n\nWhat's the best approach to non-interactively rewrite specific commit\nmessages? In this particular case, I am trying to automatically retrieve code\nreview trailers sent to the mailing list and put them into corresponding\ncommits.\n\nFor example, I have a set of commits:\n\nabcabc: This commit does foo\nbcdbcd: This commit does bar\ncdecde: This commit does baz\n\nThey were all sent to the mailing list and a maintainer sent a \"Reviewed-by\"\nto the second commit. In a usual interactive rebase session this would be:\n\npick abcabc\nreword bcdbcd\npick cdecde\n\nWhen the edit screen comes up for the bcdbcd commit, the author would manually\nstick the new trailer into the commit message. However, I can automate all\nthat away with b4 -- just need a sane strategy for non-interactively rewriting\nentire commit messages at arbitrary points in the recent history.\n\nAny pointers?\n\n-Konstantin\n"},{"id":"458214","messageId":"20220630173211.pnliwplmimcaygny@carlos-mbp-2.lan","threadId":"58089","inReplyTo":"20220630152757.yxwhijvj5xoosrws@meerkat.local","subject":"Re: Non-interactively rewording commit messages","fromName":"Carlo Marcelo Arenas Belón","fromEmail":"carenas@gmail.com","sentAt":"2022-06-30T17:32:11Z","receivedAt":"2022-06-30T17:32:18Z","isPatch":false,"sender":{"key":"carenas@gmail.com","avatar":"https://avatars.githubusercontent.com/u/76036?v=4"},"body":"On Thu, Jun 30, 2022 at 11:27:57AM -0400, Konstantin Ryabitsev wrote:\n> just need a sane strategy for non-interactively rewriting\n> entire commit messages at arbitrary points in the recent history.\n\nassuming you are still doing it by calling (albeit programmatically):\n\n  rebase --autosquash -i\n\nthen you could prepare the new message by also programmatically doing\na `git commit --fixup reword:<commit>` IMHO\n\nCarlo\n"},{"id":"458215","messageId":"CAP8UFD1Ar13wqQP0ecb37saShSVj5Gxcjdpz=pckXZ7X9TRfSQ@mail.gmail.com","threadId":"58089","inReplyTo":"20220630152757.yxwhijvj5xoosrws@meerkat.local","subject":"Re: Non-interactively rewording commit messages","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2022-06-30T17:34:54Z","receivedAt":"2022-06-30T17:35:10Z","isPatch":false,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"Hi,\n\nOn Thu, Jun 30, 2022 at 5:35 PM Konstantin Ryabitsev\n<konstantin@linuxfoundation.org> wrote:\n>\n> Hello, all:\n>\n> What's the best approach to non-interactively rewrite specific commit\n> messages? In this particular case, I am trying to automatically retrieve code\n> review trailers sent to the mailing list and put them into corresponding\n> commits.\n>\n> For example, I have a set of commits:\n>\n> abcabc: This commit does foo\n> bcdbcd: This commit does bar\n> cdecde: This commit does baz\n>\n> They were all sent to the mailing list and a maintainer sent a \"Reviewed-by\"\n> to the second commit. In a usual interactive rebase session this would be:\n>\n> pick abcabc\n> reword bcdbcd\n> pick cdecde\n>\n> When the edit screen comes up for the bcdbcd commit, the author would manually\n> stick the new trailer into the commit message. However, I can automate all\n> that away with b4 -- just need a sane strategy for non-interactively rewriting\n> entire commit messages at arbitrary points in the recent history.\n>\n> Any pointers?\n\nHave you tried `git interpret-trailers`?\n"},{"id":"458218","messageId":"20220630175421.wbgqnmym7ioazdzo@meerkat.local","threadId":"58089","inReplyTo":"CAP8UFD1Ar13wqQP0ecb37saShSVj5Gxcjdpz=pckXZ7X9TRfSQ@mail.gmail.com","subject":"Re: Non-interactively rewording commit messages","fromName":"Konstantin Ryabitsev","fromEmail":"konstantin@linuxfoundation.org","sentAt":"2022-06-30T17:54:21Z","receivedAt":"2022-06-30T17:54:27Z","isPatch":false,"sender":{"key":"konstantin@linuxfoundation.org","avatar":"https://gravatar.com/avatar/7cb8827c6de56e1bd2dea16508c6708aa43feed3bf3813bcdacecdf96ceadd79?d=mp&s=160"},"body":"On Thu, Jun 30, 2022 at 07:34:54PM +0200, Christian Couder wrote:\n> > Hello, all:\n> >\n> > What's the best approach to non-interactively rewrite specific commit\n> > messages? In this particular case, I am trying to automatically retrieve code\n> > review trailers sent to the mailing list and put them into corresponding\n> > commits.\n> >\n> > For example, I have a set of commits:\n> >\n> > abcabc: This commit does foo\n> > bcdbcd: This commit does bar\n> > cdecde: This commit does baz\n> >\n> > They were all sent to the mailing list and a maintainer sent a \"Reviewed-by\"\n> > to the second commit. In a usual interactive rebase session this would be:\n> >\n> > pick abcabc\n> > reword bcdbcd\n> > pick cdecde\n> >\n> > When the edit screen comes up for the bcdbcd commit, the author would manually\n> > stick the new trailer into the commit message. However, I can automate all\n> > that away with b4 -- just need a sane strategy for non-interactively rewriting\n> > entire commit messages at arbitrary points in the recent history.\n> >\n> > Any pointers?\n> \n> Have you tried `git interpret-trailers`?\n\nI'm aware of interpret-trailers, but unless I'm missing something large, it's\njust a way of analyzing standalone text files to retrieve or insert trailers.\nWhat I'm looking for is a way to amend arbitrary commit messages within recent\ngit history.\n\n-K\n"},{"id":"458231","messageId":"220630.86iloic97u.gmgdl@evledraar.gmail.com","threadId":"58089","inReplyTo":"20220630175421.wbgqnmym7ioazdzo@meerkat.local","subject":"Re: Non-interactively rewording commit messages","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-06-30T18:10:39Z","receivedAt":"2022-06-30T18:11:40Z","isPatch":false,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Thu, Jun 30 2022, Konstantin Ryabitsev wrote:\n\n> On Thu, Jun 30, 2022 at 07:34:54PM +0200, Christian Couder wrote:\n>> > Hello, all:\n>> >\n>> > What's the best approach to non-interactively rewrite specific commit\n>> > messages? In this particular case, I am trying to automatically retrieve code\n>> > review trailers sent to the mailing list and put them into corresponding\n>> > commits.\n>> >\n>> > For example, I have a set of commits:\n>> >\n>> > abcabc: This commit does foo\n>> > bcdbcd: This commit does bar\n>> > cdecde: This commit does baz\n>> >\n>> > They were all sent to the mailing list and a maintainer sent a \"Reviewed-by\"\n>> > to the second commit. In a usual interactive rebase session this would be:\n>> >\n>> > pick abcabc\n>> > reword bcdbcd\n>> > pick cdecde\n>> >\n>> > When the edit screen comes up for the bcdbcd commit, the author would manually\n>> > stick the new trailer into the commit message. However, I can automate all\n>> > that away with b4 -- just need a sane strategy for non-interactively rewriting\n>> > entire commit messages at arbitrary points in the recent history.\n>> >\n>> > Any pointers?\n>> \n>> Have you tried `git interpret-trailers`?\n>\n> I'm aware of interpret-trailers, but unless I'm missing something large, it's\n> just a way of analyzing standalone text files to retrieve or insert trailers.\n> What I'm looking for is a way to amend arbitrary commit messages within recent\n> git history.\n\nI think what's being suggested is that once you have a program that can\nmunge a commit message on stdin, you can combine it with rebase, git\ncommit --amend etc. to change existing commits.q\n\nThe t/t7513-interpret-trailers.sh test has some examples of munging\nexisting content.\n\n"},{"id":"458252","messageId":"Yr4S8jHKbtuBuT1z@tapette.crustytoothpaste.net","threadId":"58089","inReplyTo":"20220630152757.yxwhijvj5xoosrws@meerkat.local","subject":"Re: Non-interactively rewording commit messages","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2022-06-30T21:17:38Z","receivedAt":"2022-06-30T21:17:44Z","isPatch":false,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2022-06-30 at 15:27:57, Konstantin Ryabitsev wrote:\n> Hello, all:\n> \n> What's the best approach to non-interactively rewrite specific commit\n> messages? In this particular case, I am trying to automatically retrieve code\n> review trailers sent to the mailing list and put them into corresponding\n> commits.\n> \n> For example, I have a set of commits:\n> \n> abcabc: This commit does foo\n> bcdbcd: This commit does bar\n> cdecde: This commit does baz\n> \n> They were all sent to the mailing list and a maintainer sent a \"Reviewed-by\"\n> to the second commit. In a usual interactive rebase session this would be:\n> \n> pick abcabc\n> reword bcdbcd\n> pick cdecde\n\nYou can set GIT_SEQUENCE_EDITOR to a command which does this in-place on\nthe file...\n\n> When the edit screen comes up for the bcdbcd commit, the author would manually\n> stick the new trailer into the commit message. However, I can automate all\n> that away with b4 -- just need a sane strategy for non-interactively rewriting\n> entire commit messages at arbitrary points in the recent history.\n\n...and you can set GIT_EDITOR to modify the commit message in-place in\nwhatever way you want, and then use git rebase -i to rebase.\n-- \nbrian m. carlson (he/him or they/them)\nToronto, Ontario, CA\n"},{"id":"458274","messageId":"xmqqh741decp.fsf@gitster.g","threadId":"58089","inReplyTo":"CAP8UFD1Ar13wqQP0ecb37saShSVj5Gxcjdpz=pckXZ7X9TRfSQ@mail.gmail.com","subject":"Re: Non-interactively rewording commit messages","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-06-30T21:35:18Z","receivedAt":"2022-06-30T21:35:24Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Christian Couder <christian.couder@gmail.com> writes:\n\n>> For example, I have a set of commits:\n>>\n>> abcabc: This commit does foo\n>> bcdbcd: This commit does bar\n>> cdecde: This commit does baz\n>>\n>> They were all sent to the mailing list and a maintainer sent a \"Reviewed-by\"\n>> to the second commit. In a usual interactive rebase session this would be:\n> ...\n>\n> Have you tried `git interpret-trailers`?\n\nDo you mean a\n\n\tgit fast-export |\n\tgit interpret-trailers |\n\tgit fast-import\n\npipeline?\n"},{"id":"458332","messageId":"CABPp-BHX5H1co+cMS2LEt=NYB5==5e4YK_sK=h_O1-zxaNocAA@mail.gmail.com","threadId":"58089","inReplyTo":"20220630152757.yxwhijvj5xoosrws@meerkat.local","subject":"Re: Non-interactively rewording commit messages","fromName":"Elijah Newren","fromEmail":"newren@gmail.com","sentAt":"2022-07-01T04:01:33Z","receivedAt":"2022-07-01T04:04:39Z","isPatch":false,"sender":{"key":"newren@gmail.com","avatar":"https://avatars.githubusercontent.com/u/5455730?v=4"},"body":"On Thu, Jun 30, 2022 at 8:35 AM Konstantin Ryabitsev\n<konstantin@linuxfoundation.org> wrote:\n>\n> Hello, all:\n>\n> What's the best approach to non-interactively rewrite specific commit\n> messages? In this particular case, I am trying to automatically retrieve code\n> review trailers sent to the mailing list and put them into corresponding\n> commits.\n>\n> For example, I have a set of commits:\n>\n> abcabc: This commit does foo\n> bcdbcd: This commit does bar\n> cdecde: This commit does baz\n>\n> They were all sent to the mailing list and a maintainer sent a \"Reviewed-by\"\n> to the second commit. In a usual interactive rebase session this would be:\n>\n> pick abcabc\n> reword bcdbcd\n> pick cdecde\n>\n> When the edit screen comes up for the bcdbcd commit, the author would manually\n> stick the new trailer into the commit message. However, I can automate all\n> that away with b4 -- just need a sane strategy for non-interactively rewriting\n> entire commit messages at arbitrary points in the recent history.\n>\n> Any pointers?\n\nOne possibility would be to tweak\nhttps://github.com/newren/git-filter-repo/blob/main/contrib/filter-repo-demos/signed-off-by,\nmodifying the line setting the 'trailer' variable to make it be a\nReviewed-by rather than a Signed-off-by.  You could tweak the script\nto also make other automated commit message changes unrelated to any\ntrailers, if you wanted.\n\n(There's also the slightly less careful way of adding trailers shown\nover at https://github.com/newren/git-filter-repo/blob/main/Documentation/converting-from-filter-branch.md#rewriting-commit-messages----adding-text,\nbut the literal appending instead of determining whether to also first\nadd one or more newlines before the trailer might not be exactly what\nyou want.)\n"},{"id":"458379","messageId":"CAP8UFD11yVhNK0zr1A9AkTyEOHfC9fBjgZTNHDWHA0=zmJWprQ@mail.gmail.com","threadId":"58089","inReplyTo":"xmqqh741decp.fsf@gitster.g","subject":"Re: Non-interactively rewording commit messages","fromName":"Christian Couder","fromEmail":"christian.couder@gmail.com","sentAt":"2022-07-01T11:10:15Z","receivedAt":"2022-07-01T11:10:47Z","isPatch":false,"sender":{"key":"christian.couder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/208954?v=4"},"body":"On Thu, Jun 30, 2022 at 11:35 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Christian Couder <christian.couder@gmail.com> writes:\n\n> > Have you tried `git interpret-trailers`?\n>\n> Do you mean a\n>\n>         git fast-export |\n>         git interpret-trailers |\n>         git fast-import\n>\n> pipeline?\n\nI was thinking about using ways that are described a bit in the `git\ninterpret-trailers` doc. And I was thinking about using  ̀git rebase\n-i` and either adding \"exec ...\" lines to the todo list (possibly with\n`--exec ...` ) or maybe using \"reword ...\"\n\nAbout ways that are described in the `git interpret-trailers` doc, there is:\n\n* the following example with `git format-patch`:\n\n      •   Extract the last commit as a patch, and add a Cc and a\nReviewed-by trailer to it:\n\n              $ git format-patch -1\n              0001-foo.patch\n              $ git interpret-trailers --trailer 'Cc: Alice\n<alice@example.com>' --trailer 'Reviewed-by: Bob <bob@example.com>'\n0001-foo.patch >0001-bar.patch\n\n* the example with a commit-msg hook that uses git interpret-trailers\n\nBTW using interpret-trailers' --in-place option might be better than\nhandling files the way it's done in both these examples.\n"},{"id":"458385","messageId":"7nrs9832-679s-9s39-56n6-ro31rn84p0o2@tzk.qr","threadId":"58089","inReplyTo":"20220630152757.yxwhijvj5xoosrws@meerkat.local","subject":"Re: Non-interactively rewording commit messages","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2022-07-01T13:37:37Z","receivedAt":"2022-07-01T13:37:43Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Konstantin,\n\nOn Thu, 30 Jun 2022, Konstantin Ryabitsev wrote:\n\n> What's the best approach to non-interactively rewrite specific commit\n> messages? In this particular case, I am trying to automatically retrieve code\n> review trailers sent to the mailing list and put them into corresponding\n> commits.\n>\n> For example, I have a set of commits:\n>\n> abcabc: This commit does foo\n> bcdbcd: This commit does bar\n> cdecde: This commit does baz\n>\n> They were all sent to the mailing list and a maintainer sent a \"Reviewed-by\"\n> to the second commit. In a usual interactive rebase session this would be:\n>\n> pick abcabc\n> reword bcdbcd\n> pick cdecde\n>\n> When the edit screen comes up for the bcdbcd commit, the author would manually\n> stick the new trailer into the commit message. However, I can automate all\n> that away with b4 -- just need a sane strategy for non-interactively rewriting\n> entire commit messages at arbitrary points in the recent history.\n>\n> Any pointers?\n\nThe quickest (in terms of script size) might be to craft an `amend!`\ncommit, something like this:\n\n\tgit commit --allow-empty -m \"$(printf 'amend! bcdbcd\\n\\n' &&\n\t\tgit cat-file commit bcdbcd |\n\t\tsed -e '1,/^$/d' \\\n\t\t -e '{:1;${s/^/Reviewed-by: M A Intainer <maintainer@example.org>\\n/;b};N;/\\n$/b;b1}')\"\n\nand then running an \"interactive\" rebase with `:` as the editor:\n\n\tGIT_SEQUENCE_EDITOR=: GIT_EDITOR=: git rebase -i --autosquash HEAD~3\n\n(The `sed` call is admittedly a bit horrible, it prepends the\n`Reviewed-by:` footer to the last paragraph, if it needs to be _appended_,\nit can be greatly simplified.)\n\nCiao,\nDscho\n"},{"id":"458402","messageId":"20220701181833.yf3wmg2k3vyk4v6n@nitro.local","threadId":"58089","inReplyTo":"CABPp-BHX5H1co+cMS2LEt=NYB5==5e4YK_sK=h_O1-zxaNocAA@mail.gmail.com","subject":"Re: Non-interactively rewording commit messages","fromName":"Konstantin Ryabitsev","fromEmail":"konstantin@linuxfoundation.org","sentAt":"2022-07-01T18:18:33Z","receivedAt":"2022-07-01T18:18:44Z","isPatch":false,"sender":{"key":"konstantin@linuxfoundation.org","avatar":"https://gravatar.com/avatar/7cb8827c6de56e1bd2dea16508c6708aa43feed3bf3813bcdacecdf96ceadd79?d=mp&s=160"},"body":"On Thu, Jun 30, 2022 at 09:01:33PM -0700, Elijah Newren wrote:\n> One possibility would be to tweak\n> https://github.com/newren/git-filter-repo/blob/main/contrib/filter-repo-demos/signed-off-by,\n> modifying the line setting the 'trailer' variable to make it be a\n> Reviewed-by rather than a Signed-off-by.  You could tweak the script\n> to also make other automated commit message changes unrelated to any\n> trailers, if you wanted.\n\nOh, this is neat, I was unaware of git-filter-repo. It looks like exactly what\nI need for my purposes -- maybe I can just use it as a subproject. Thanks for\nthe suggestion!\n\n-K\n"}]}