git cherry-pick -x: link in details instead of in summary
Given a commit with the message "foo", i.e. wi开发者_高级运维th 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.
But how can I make git make the comment look like below without editing the comment manually?
foo(cherry picked from commit eb42a6475d2c2e4fff7a1b626ce6e27eec21e886)
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"
精彩评论