git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Non-interactively rewording commit messages

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Jul 1, 2022, 13:37 UTC
Message-ID
<7nrs9832-679s-9s39-56n6-ro31rn84p0o2@tzk.qr>
In-Reply-To
<20220630152757.yxwhijvj5xoosrws@meerkat.local>
Hi Konstantin,
On Thu, 30 Jun 2022, Konstantin Ryabitsev wrote:
Show 24 quoted lines
> 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

Previous: Konstantin Ryabitsev
Message 11 of 11 in “Non-interactively rewording commit messages”
  1. Konstantin RyabitsevJun 30, 2022
  2. Carlo Marcelo Arenas BelónJun 30, 2022
  3. Christian CouderJun 30, 2022
  4. Konstantin RyabitsevJun 30, 2022
  5. Ævar Arnfjörð BjarmasonJun 30, 2022
  6. Junio C HamanoJun 30, 2022
  7. Christian CouderJul 1, 2022
  8. brian m. carlsonJun 30, 2022
  9. Elijah NewrenJul 1, 2022
  10. Konstantin RyabitsevJul 1, 2022
  11. Johannes SchindelinJul 1, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.