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

foo
(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 does this cherry-pick have a conflict?
  • Cherry-picking from git to svn (or, How to keep a project history in git and releases in svn)
  • Why doesn't git cherry-pick override modification in current branch if their is different?
  • git cherry-pick says “…38c74d is a merge but no -m option was given”
  • How to git cherry-pick from sibling directories?
  • Git Cherry-pick vs Merge Workflow
  • But how can I make git make the comment look like below without editing the comment manually?

    foo

    (cherry picked from commit eb42a6475d2c2e4fff7a1b626ce6e27eec21e886)

  • How do I revert a git-svn branch to SVN HEAD?
  • Able to push to all git remotes with the one command?
  • How do you merge changes on non-master branches from a forked github repository?
  • Correct way to compare same file in different branches
  • Error publishing master branch to GitHub from VS.NET
  • ERROR: Repository not found message given when following the instructions for Jekyll-Bootstrap
  • 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:

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