git cherry-pick -x: link in details instead of in summary

Given a commit with the message “foo”, i.e. with only a summary part, I do git cherry-pick -x the_commit. The result is a new commit with message

(cherry picked from commit eb42a6475d2c2e4fff7a1b626ce6e27eec21e886)

Now that’s not good, because it is a two-line summary, which seems like a bug in git.

  • Backport changes from renamed file
  • git cherry-pick: output resulting new commit sha
  • Why git gives priority to a cherry-pick commit over the revert commit?
  • How to cherry-pick from stash in git?
  • Git cherry-pick: how to regenerate change id?
  • Are cherry pick merges appropriate in this scheme?
  • But how can I make git make the comment look like below without editing the comment manually?


    (cherry picked from commit eb42a6475d2c2e4fff7a1b626ce6e27eec21e886)

  • Can I use .gitignore_global to ignore file for all users over multiple repos?
  • How does “index f2e4113..d4b9bfc 100644” in git diff correspond to SHA1 ID in gitk?
  • Git commit -am does not work on initial commit. Why?
  • Move a commit to a different branch
  • Is it safe to delete or remerge a Gitlow feature branch after it was previously merged into the develop branch?
  • Upload AAR library to local maven repository and share build.gradle in git
  • One Solution collect form web for “git cherry-pick -x: link in details instead of in summary”

    You’re right that it seems like an oversight. You could send an email to the git mailing list and see what they think! For now you’ll have to handle it yourself, though.

    The good way to deal with this would be to avoid it altogether: make the original commit message good. If it’s already multi-line, with the blank line in there, the appended line from the cherry-pick will not screw up the format.

    To work around it, given that the cherry-picked commit has a one-line message, as you say, you can use the -e option for cherry-pick. If you’re using Vim, worst case you have to hit ggo<Esc>ZZ to take care of it.

    Or you could write a prepare-commit-msg hook. All you should need in it is:

    sed -i '2s/^(cherry picked/\n&' "$1"
    Git Baby is a git and github fan, let's start git clone.