Skip to content

Instantly share code, notes, and snippets.

@drmingdrmer
Last active July 12, 2019 06:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drmingdrmer/7a59b2536e1de5bc6f8696a32a7b58e8 to your computer and use it in GitHub Desktop.
Save drmingdrmer/7a59b2536e1de5bc6f8696a32a7b58e8 to your computer and use it in GitHub Desktop.
Batch replace word in commit messages with: git history-msg typo type origin/master..mydev_branch
#!/bin/sh
usage(){
cat <<-END
git history-msg <from> <to> <spec>
Replace word <from> to <to> in commit message.
Install:
copy it into /usr/local/bin/ or somewhere PATH env can find.
Usage:
To replace "typo" with "type" in all commit messages from origin/master to
branch mydev_branch:
git history-msg typo type origin/master..mydev_branch
END
exit 0
}
from="$1"
to="$2"
shift
shift
script="$(cat <<-END
sed 's/$from/$to/g'
END
)"
echo "script: ($script)"
git filter-branch -f --msg-filter "$script" "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment