4

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.

2
  • Technically it's not a re-base after each change, it's a re-commit. Commented Nov 12, 2013 at 19:30
  • This is the same as what I would like to do: to change a referenced issue/ticket/bug ID in each commit message (~25 consecutive commits) with git rebase & sed /old/new/.... Commented Oct 6, 2018 at 20:34

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Another method: set the "editor" to a command that does the change without human interaction. E.g., write a script that can runssed -i '' to add a blank line after the first line. Make sure the script works well, then use EDITOR=... git rebase .... Rig the script to run the real editor when run on the set of pick-etc commands, and to script the edit when run on each commit-message (which has a predictable file name).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.