1

When cherry-picking a range of commits I can use -x to append the line "(cherry picked from commit [commit])" to each commit message.

How do I customize this line to instead say "Backport of [commit] from master" ?

Oskar Persson
  • 6,605
  • 15
  • 63
  • 124

1 Answers1

1

Use -e or --edit with your git cherry-pick command; this will invoke your chosen editor on the commit message. You can then change the appropriate line manually.

If you want to automate the commit-message change, choose as your "editor" a script / program that will:

  • open the file whose name is passed as an argument;
  • find and replace the line;
  • write the result back to the file whose name was passed; and
  • exit with a zero status to signal success.

Do this just for the one git cherry-pick command, by setting $GIT_EDITOR (environment variable) or core.editor (Git configuration setting) for the duration of the one command:

GIT_EDITOR=<path/to/script> git cherry-pick -x -e <commit-specifier>

or:

git -c core.editor=<path/to/script> cherry-pick -x -e <commit-specifier>

(Consider using sed -i "", for instance, to construct the editor-script.)

torek
  • 448,244
  • 59
  • 642
  • 775