Search code examples
gitrebase

Git prepend all commit messages in interactive rebase


I ran an interactive rebase up to commit abcdef.

git rebase -i abcdef

In the editor - Vim I changed all pick hash lines to

reword hash PREFIX: Original commit message using this vim command

%s/pick \(\w\{7}\)/reword \1 PREFIX:/

but then git goes on to prompt me to edit the message for every commit. Is there a simple way to batch this process?


Solution

  • GIT_EDITOR='sed -i "1s/^/PREFIX: /"' GIT_SEQUENCE_EDITOR=vim \
            git rebase -i abcdef
    

    or alternately you could

    git -c core.editor='sed -i "1s/^/PREFIX: /"' \
            -c sequence.editor=vim \
            rebase -i abcdef
    

    if you don't want to use the environment overrides.

    If you know you're going to reword them all you could even sed the sequence, GIT_SEQUENCE_EDITOR='sed -i "s/^pick/reword/"'.