简体   繁体   中英

Launch $EDITOR from git-filter-branch --msg-filter

I want to change all my commits messages to translate them in another language.

I know I can achieve this using git-filter-branch --msg-filter, but I don't want to replace the messages with any pattern, instead, I want to open each commit message in my editor, change it and save, like I do when I use reword in git-rebase --interactive.

git filter-branch --msg-filter 'cat > ~/msg && 
  vim >&2 <&1 ~/msg && 
  cat ~/msg' HEAD^^^^..HEAD

This will allow you to edit with vim the messages of the last 4 commits. Add -f if you're doing this a second time to overwrite the backup.

If you rebase your branch, you can edit any/all of the commit messages.

The tricky thing about Git is it uses the commit messages as part of the commit itself, so your branches will diverge.

Just do (on your branch):

git rebase -i master

or if you want to preserve merge commits (thanks danillonunes and Adam D.)

git rebase -i master --preserve-merges 

When you are presented with the editor, change the first column from pick to edit and you will get a chance to change every commit message.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM