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.

  • Why is git log --cherry-pick not removing equivalent commits?
  • cherry-picking with git-svn
  • cherry-picking with git with a conflict
  • Extracting git history for part of a git repo to create a git submodule — cherry-pick?
  • git cherry-pick to another branch
  • Why doesn't git cherry-pick override modification in current branch if their is different?
  • But how can I make git make the comment look like below without editing the comment manually?


    (cherry picked from commit eb42a6475d2c2e4fff7a1b626ce6e27eec21e886)

  • How can I mirror a project hosted on launchpad on github?
  • Is there a robust way of checking whether a prospective Git alias name is available?
  • git rebase could not execute editor
  • Recreating Gitolite-admin Repo
  • How can I view the output of `git show` in a diff viewer like meld, kdiff3, etc
  • Git always merge without a fast-forward, except for when pulling?
  • 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.