Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to edit multiple commit messages at once during rebase?

Tags:

git

I want to reformat the commit message of several commits (30 or so). I had neglected to add a newline after the "short" message in many commits, which is causing issues as described in this question: How to output git log with the first line only?, so I want to rewrite the commit messages with this newline included.

I ran the command git rebase -i -p <commit-id of last good commit>, as explained in this answer: How do I edit an incorrect commit message in Git?, then in the editor window that opens, I replaced pick with reword for the commits whose message I want to edit.

This results in git opening text editor one at a time per commit. I guess it is designed this way because git needs to do a rebase after each change.

However, in this case, I am only changing the commit messages, and not changing any files. Is it possible to speed this up, by opening all the text editor windows at once?

For example, if these windows could be opened in multiple buffers of one text editor process (most text editors support this), then I could use a multi-buffer operation, like the bufdo command of gvim.

like image 535
Masked Man Avatar asked Oct 25 '25 11:10

Masked Man


1 Answers

The easy way: just put the right key sequence in your copy-paste buffer and middle-click (or use your terminal emulator's paste functionality) to apply.

The more involved way: use git filter-branch. For example, to add an empty line in second position, you'd likely use something like this:

git filter-branch --msg-filter 'sed "1a\\\\"' from..

where from is a ref to your last good commit.

like image 198
JB. Avatar answered Oct 27 '25 00:10

JB.