Skip to content

Instantly share code, notes, and snippets.

@openjck
Created December 11, 2014 17:08
Show Gist options
  • Save openjck/291f12b130b3d9afc4e7 to your computer and use it in GitHub Desktop.
Save openjck/291f12b130b3d9afc4e7 to your computer and use it in GitHub Desktop.
Using sed and filter-branch to prepend and append to Git commit messages without newlines
# Prepending text to the five most recent commit messages:
git filter-branch --msg-filter 'sed "s/\(.*\)/[prepended text] \1/g"' HEAD~5..HEAD
# Appending text to the five most recent commit messages:
git filter-branch --msg-filter 'sed "s/\(.*\)/\1 [appended text]/g"' HEAD~5..HEAD
@codingforfun
Copy link

Note that this prepends line by line. I.e. if you have multiline commit messages each line gets prepended the string.

@c0d3z3r0
Copy link

c0d3z3r0 commented Nov 1, 2022

Note that this prepends line by line. I.e. if you have multiline commit messages each line gets prepended the string.

# Prepending on the first line only:
git filter-branch -f --msg-filter 'sed "1 s/^/[prepended text]/g"' HEAD~5..HEAD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment