# Non-interactively rewording commit messages

11 messages from 2022-06-30 to 2022-07-01. Participants: Konstantin Ryabitsev, Carlo Marcelo Arenas Belón, Christian Couder, Ævar Arnfjörð Bjarmason, brian m. carlson, Junio C Hamano, Elijah Newren, Johannes Schindelin.
Thread: https://gitlist.dev/t/58089

## Konstantin Ryabitsev, 2022-06-30 15:27

Subject: Non-interactively rewording commit messages
Message-ID: <20220630152757.yxwhijvj5xoosrws@meerkat.local>
URL: https://gitlist.dev/e/20220630152757.yxwhijvj5xoosrws%40meerkat.local

```
Hello, all:

What's the best approach to non-interactively rewrite specific commit
messages? In this particular case, I am trying to automatically retrieve code
review trailers sent to the mailing list and put them into corresponding
commits.

For example, I have a set of commits:

abcabc: This commit does foo
bcdbcd: This commit does bar
cdecde: This commit does baz

They were all sent to the mailing list and a maintainer sent a "Reviewed-by"
to the second commit. In a usual interactive rebase session this would be:

pick abcabc
reword bcdbcd
pick cdecde

When the edit screen comes up for the bcdbcd commit, the author would manually
stick the new trailer into the commit message. However, I can automate all
that away with b4 -- just need a sane strategy for non-interactively rewriting
entire commit messages at arbitrary points in the recent history.

Any pointers?

-Konstantin

```

## Carlo Marcelo Arenas Belón, 2022-06-30 17:32

Subject: Re: Non-interactively rewording commit messages
Message-ID: <20220630173211.pnliwplmimcaygny@carlos-mbp-2.lan>
URL: https://gitlist.dev/e/20220630173211.pnliwplmimcaygny%40carlos-mbp-2.lan
In-Reply-To: <20220630152757.yxwhijvj5xoosrws@meerkat.local>

```
On Thu, Jun 30, 2022 at 11:27:57AM -0400, Konstantin Ryabitsev wrote:
> just need a sane strategy for non-interactively rewriting
> entire commit messages at arbitrary points in the recent history.

assuming you are still doing it by calling (albeit programmatically):

  rebase --autosquash -i

then you could prepare the new message by also programmatically doing
a `git commit --fixup reword:<commit>` IMHO

Carlo

```

## Christian Couder, 2022-06-30 17:34

Subject: Re: Non-interactively rewording commit messages
Message-ID: <CAP8UFD1Ar13wqQP0ecb37saShSVj5Gxcjdpz=pckXZ7X9TRfSQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAP8UFD1Ar13wqQP0ecb37saShSVj5Gxcjdpz%3DpckXZ7X9TRfSQ%40mail.gmail.com
In-Reply-To: <20220630152757.yxwhijvj5xoosrws@meerkat.local>

```
Hi,

On Thu, Jun 30, 2022 at 5:35 PM Konstantin Ryabitsev
<konstantin@linuxfoundation.org> wrote:
>
> Hello, all:
>
> What's the best approach to non-interactively rewrite specific commit
> messages? In this particular case, I am trying to automatically retrieve code
> review trailers sent to the mailing list and put them into corresponding
> commits.
>
> For example, I have a set of commits:
>
> abcabc: This commit does foo
> bcdbcd: This commit does bar
> cdecde: This commit does baz
>
> They were all sent to the mailing list and a maintainer sent a "Reviewed-by"
> to the second commit. In a usual interactive rebase session this would be:
>
> pick abcabc
> reword bcdbcd
> pick cdecde
>
> When the edit screen comes up for the bcdbcd commit, the author would manually
> stick the new trailer into the commit message. However, I can automate all
> that away with b4 -- just need a sane strategy for non-interactively rewriting
> entire commit messages at arbitrary points in the recent history.
>
> Any pointers?

Have you tried `git interpret-trailers`?

```

## Konstantin Ryabitsev, 2022-06-30 17:54

Subject: Re: Non-interactively rewording commit messages
Message-ID: <20220630175421.wbgqnmym7ioazdzo@meerkat.local>
URL: https://gitlist.dev/e/20220630175421.wbgqnmym7ioazdzo%40meerkat.local
In-Reply-To: <CAP8UFD1Ar13wqQP0ecb37saShSVj5Gxcjdpz=pckXZ7X9TRfSQ@mail.gmail.com>

```
On Thu, Jun 30, 2022 at 07:34:54PM +0200, Christian Couder wrote:
> > Hello, all:
> >
> > What's the best approach to non-interactively rewrite specific commit
> > messages? In this particular case, I am trying to automatically retrieve code
> > review trailers sent to the mailing list and put them into corresponding
> > commits.
> >
> > For example, I have a set of commits:
> >
> > abcabc: This commit does foo
> > bcdbcd: This commit does bar
> > cdecde: This commit does baz
> >
> > They were all sent to the mailing list and a maintainer sent a "Reviewed-by"
> > to the second commit. In a usual interactive rebase session this would be:
> >
> > pick abcabc
> > reword bcdbcd
> > pick cdecde
> >
> > When the edit screen comes up for the bcdbcd commit, the author would manually
> > stick the new trailer into the commit message. However, I can automate all
> > that away with b4 -- just need a sane strategy for non-interactively rewriting
> > entire commit messages at arbitrary points in the recent history.
> >
> > Any pointers?
> 
> Have you tried `git interpret-trailers`?

I'm aware of interpret-trailers, but unless I'm missing something large, it's
just a way of analyzing standalone text files to retrieve or insert trailers.
What I'm looking for is a way to amend arbitrary commit messages within recent
git history.

-K

```

## Ævar Arnfjörð Bjarmason, 2022-06-30 18:10

Subject: Re: Non-interactively rewording commit messages
Message-ID: <220630.86iloic97u.gmgdl@evledraar.gmail.com>
URL: https://gitlist.dev/e/220630.86iloic97u.gmgdl%40evledraar.gmail.com
In-Reply-To: <20220630175421.wbgqnmym7ioazdzo@meerkat.local>

```

On Thu, Jun 30 2022, Konstantin Ryabitsev wrote:

> On Thu, Jun 30, 2022 at 07:34:54PM +0200, Christian Couder wrote:
>> > Hello, all:
>> >
>> > What's the best approach to non-interactively rewrite specific commit
>> > messages? In this particular case, I am trying to automatically retrieve code
>> > review trailers sent to the mailing list and put them into corresponding
>> > commits.
>> >
>> > For example, I have a set of commits:
>> >
>> > abcabc: This commit does foo
>> > bcdbcd: This commit does bar
>> > cdecde: This commit does baz
>> >
>> > They were all sent to the mailing list and a maintainer sent a "Reviewed-by"
>> > to the second commit. In a usual interactive rebase session this would be:
>> >
>> > pick abcabc
>> > reword bcdbcd
>> > pick cdecde
>> >
>> > When the edit screen comes up for the bcdbcd commit, the author would manually
>> > stick the new trailer into the commit message. However, I can automate all
>> > that away with b4 -- just need a sane strategy for non-interactively rewriting
>> > entire commit messages at arbitrary points in the recent history.
>> >
>> > Any pointers?
>> 
>> Have you tried `git interpret-trailers`?
>
> I'm aware of interpret-trailers, but unless I'm missing something large, it's
> just a way of analyzing standalone text files to retrieve or insert trailers.
> What I'm looking for is a way to amend arbitrary commit messages within recent
> git history.

I think what's being suggested is that once you have a program that can
munge a commit message on stdin, you can combine it with rebase, git
commit --amend etc. to change existing commits.q

The t/t7513-interpret-trailers.sh test has some examples of munging
existing content.


```

## brian m. carlson, 2022-06-30 21:17

Subject: Re: Non-interactively rewording commit messages
Message-ID: <Yr4S8jHKbtuBuT1z@tapette.crustytoothpaste.net>
URL: https://gitlist.dev/e/Yr4S8jHKbtuBuT1z%40tapette.crustytoothpaste.net
In-Reply-To: <20220630152757.yxwhijvj5xoosrws@meerkat.local>

```
On 2022-06-30 at 15:27:57, Konstantin Ryabitsev wrote:
> Hello, all:
> 
> What's the best approach to non-interactively rewrite specific commit
> messages? In this particular case, I am trying to automatically retrieve code
> review trailers sent to the mailing list and put them into corresponding
> commits.
> 
> For example, I have a set of commits:
> 
> abcabc: This commit does foo
> bcdbcd: This commit does bar
> cdecde: This commit does baz
> 
> They were all sent to the mailing list and a maintainer sent a "Reviewed-by"
> to the second commit. In a usual interactive rebase session this would be:
> 
> pick abcabc
> reword bcdbcd
> pick cdecde

You can set GIT_SEQUENCE_EDITOR to a command which does this in-place on
the file...

> When the edit screen comes up for the bcdbcd commit, the author would manually
> stick the new trailer into the commit message. However, I can automate all
> that away with b4 -- just need a sane strategy for non-interactively rewriting
> entire commit messages at arbitrary points in the recent history.

...and you can set GIT_EDITOR to modify the commit message in-place in
whatever way you want, and then use git rebase -i to rebase.
-- 
brian m. carlson (he/him or they/them)
Toronto, Ontario, CA

```

## Junio C Hamano, 2022-06-30 21:35

Subject: Re: Non-interactively rewording commit messages
Message-ID: <xmqqh741decp.fsf@gitster.g>
URL: https://gitlist.dev/e/xmqqh741decp.fsf%40gitster.g
In-Reply-To: <CAP8UFD1Ar13wqQP0ecb37saShSVj5Gxcjdpz=pckXZ7X9TRfSQ@mail.gmail.com>

```
Christian Couder <christian.couder@gmail.com> writes:

>> For example, I have a set of commits:
>>
>> abcabc: This commit does foo
>> bcdbcd: This commit does bar
>> cdecde: This commit does baz
>>
>> They were all sent to the mailing list and a maintainer sent a "Reviewed-by"
>> to the second commit. In a usual interactive rebase session this would be:
> ...
>
> Have you tried `git interpret-trailers`?

Do you mean a

	git fast-export |
	git interpret-trailers |
	git fast-import

pipeline?

```

## Elijah Newren, 2022-07-01 04:01

Subject: Re: Non-interactively rewording commit messages
Message-ID: <CABPp-BHX5H1co+cMS2LEt=NYB5==5e4YK_sK=h_O1-zxaNocAA@mail.gmail.com>
URL: https://gitlist.dev/e/CABPp-BHX5H1co%2BcMS2LEt%3DNYB5%3D%3D5e4YK_sK%3Dh_O1-zxaNocAA%40mail.gmail.com
In-Reply-To: <20220630152757.yxwhijvj5xoosrws@meerkat.local>

```
On Thu, Jun 30, 2022 at 8:35 AM Konstantin Ryabitsev
<konstantin@linuxfoundation.org> wrote:
>
> Hello, all:
>
> What's the best approach to non-interactively rewrite specific commit
> messages? In this particular case, I am trying to automatically retrieve code
> review trailers sent to the mailing list and put them into corresponding
> commits.
>
> For example, I have a set of commits:
>
> abcabc: This commit does foo
> bcdbcd: This commit does bar
> cdecde: This commit does baz
>
> They were all sent to the mailing list and a maintainer sent a "Reviewed-by"
> to the second commit. In a usual interactive rebase session this would be:
>
> pick abcabc
> reword bcdbcd
> pick cdecde
>
> When the edit screen comes up for the bcdbcd commit, the author would manually
> stick the new trailer into the commit message. However, I can automate all
> that away with b4 -- just need a sane strategy for non-interactively rewriting
> entire commit messages at arbitrary points in the recent history.
>
> Any pointers?

One possibility would be to tweak
https://github.com/newren/git-filter-repo/blob/main/contrib/filter-repo-demos/signed-off-by,
modifying the line setting the 'trailer' variable to make it be a
Reviewed-by rather than a Signed-off-by.  You could tweak the script
to also make other automated commit message changes unrelated to any
trailers, if you wanted.

(There's also the slightly less careful way of adding trailers shown
over at https://github.com/newren/git-filter-repo/blob/main/Documentation/converting-from-filter-branch.md#rewriting-commit-messages----adding-text,
but the literal appending instead of determining whether to also first
add one or more newlines before the trailer might not be exactly what
you want.)

```

## Christian Couder, 2022-07-01 11:10

Subject: Re: Non-interactively rewording commit messages
Message-ID: <CAP8UFD11yVhNK0zr1A9AkTyEOHfC9fBjgZTNHDWHA0=zmJWprQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAP8UFD11yVhNK0zr1A9AkTyEOHfC9fBjgZTNHDWHA0%3DzmJWprQ%40mail.gmail.com
In-Reply-To: <xmqqh741decp.fsf@gitster.g>

```
On Thu, Jun 30, 2022 at 11:35 PM Junio C Hamano <gitster@pobox.com> wrote:
>
> Christian Couder <christian.couder@gmail.com> writes:

> > Have you tried `git interpret-trailers`?
>
> Do you mean a
>
>         git fast-export |
>         git interpret-trailers |
>         git fast-import
>
> pipeline?

I was thinking about using ways that are described a bit in the `git
interpret-trailers` doc. And I was thinking about using  ̀git rebase
-i` and either adding "exec ..." lines to the todo list (possibly with
`--exec ...` ) or maybe using "reword ..."

About ways that are described in the `git interpret-trailers` doc, there is:

* the following example with `git format-patch`:

      •   Extract the last commit as a patch, and add a Cc and a
Reviewed-by trailer to it:

              $ git format-patch -1
              0001-foo.patch
              $ git interpret-trailers --trailer 'Cc: Alice
<alice@example.com>' --trailer 'Reviewed-by: Bob <bob@example.com>'
0001-foo.patch >0001-bar.patch

* the example with a commit-msg hook that uses git interpret-trailers

BTW using interpret-trailers' --in-place option might be better than
handling files the way it's done in both these examples.

```

## Johannes Schindelin, 2022-07-01 13:37

Subject: Re: Non-interactively rewording commit messages
Message-ID: <7nrs9832-679s-9s39-56n6-ro31rn84p0o2@tzk.qr>
URL: https://gitlist.dev/e/7nrs9832-679s-9s39-56n6-ro31rn84p0o2%40tzk.qr
In-Reply-To: <20220630152757.yxwhijvj5xoosrws@meerkat.local>

```
Hi Konstantin,

On Thu, 30 Jun 2022, Konstantin Ryabitsev wrote:

> What's the best approach to non-interactively rewrite specific commit
> messages? In this particular case, I am trying to automatically retrieve code
> review trailers sent to the mailing list and put them into corresponding
> commits.
>
> For example, I have a set of commits:
>
> abcabc: This commit does foo
> bcdbcd: This commit does bar
> cdecde: This commit does baz
>
> They were all sent to the mailing list and a maintainer sent a "Reviewed-by"
> to the second commit. In a usual interactive rebase session this would be:
>
> pick abcabc
> reword bcdbcd
> pick cdecde
>
> When the edit screen comes up for the bcdbcd commit, the author would manually
> stick the new trailer into the commit message. However, I can automate all
> that away with b4 -- just need a sane strategy for non-interactively rewriting
> entire commit messages at arbitrary points in the recent history.
>
> Any pointers?

The quickest (in terms of script size) might be to craft an `amend!`
commit, something like this:

	git commit --allow-empty -m "$(printf 'amend! bcdbcd\n\n' &&
		git cat-file commit bcdbcd |
		sed -e '1,/^$/d' \
		 -e '{:1;${s/^/Reviewed-by: M A Intainer <maintainer@example.org>\n/;b};N;/\n$/b;b1}')"

and then running an "interactive" rebase with `:` as the editor:

	GIT_SEQUENCE_EDITOR=: GIT_EDITOR=: git rebase -i --autosquash HEAD~3

(The `sed` call is admittedly a bit horrible, it prepends the
`Reviewed-by:` footer to the last paragraph, if it needs to be _appended_,
it can be greatly simplified.)

Ciao,
Dscho

```

## Konstantin Ryabitsev, 2022-07-01 18:18

Subject: Re: Non-interactively rewording commit messages
Message-ID: <20220701181833.yf3wmg2k3vyk4v6n@nitro.local>
URL: https://gitlist.dev/e/20220701181833.yf3wmg2k3vyk4v6n%40nitro.local
In-Reply-To: <CABPp-BHX5H1co+cMS2LEt=NYB5==5e4YK_sK=h_O1-zxaNocAA@mail.gmail.com>

```
On Thu, Jun 30, 2022 at 09:01:33PM -0700, Elijah Newren wrote:
> One possibility would be to tweak
> https://github.com/newren/git-filter-repo/blob/main/contrib/filter-repo-demos/signed-off-by,
> modifying the line setting the 'trailer' variable to make it be a
> Reviewed-by rather than a Signed-off-by.  You could tweak the script
> to also make other automated commit message changes unrelated to any
> trailers, if you wanted.

Oh, this is neat, I was unaware of git-filter-repo. It looks like exactly what
I need for my purposes -- maybe I can just use it as a subproject. Thanks for
the suggestion!

-K

```
