2

I have used git cherry-pick to push a commit from branch a to branch b .

git checkout branch b

git cherry-pick commit-hash

Which worked fine but I couldn't find a way to update the push comment. Whatever comment was provided earlier for branch a same is reflecting for branch b as well. Is there a way I can modify push comment before actually pushing the commit to my origin branch?

JavaSeeker
  • 53
  • 1
  • 1
  • 8
  • 2
    As in the answers below, you can amend or use `-n`, but the shortest command is `git cherry-pick -e `. The `-e` option is short for `--edit` (you can spell it out if you like); that tells Git to open the editor on the prepared commit message. – torek Apr 03 '20 at 09:31
  • @torek I read that in the docs. When I tried it I got `fatal: bad revision ` – user1007074 Jul 05 '22 at 23:06
  • @user1007074: A "commit specifier" is what you find listed in [the gitrevisions documentation](https://git-scm.com/docs/gitrevisions). Commit *messages* are not commit specifiers unless you use them with some additional searching syntax. Typically though you'd run `git log` to find the commit of interest, then use your mouse to cut out the *hash ID*, and paste that in to your `git cherry-pick` command. – torek Jul 06 '22 at 00:32

2 Answers2

4

Beside git commit --amend, you can also use git cherry-pick <commit-hash> -n && git commit. -n instructs git cherry-pick to apply the changes only and not to create the commit. You can specify the commit message in the subsequent git commit.

ElpieKay
  • 27,194
  • 6
  • 32
  • 53
1

If I understood your question correctly : you want to edit the message of the commit you just cherry-picked before pushing the whole branch to github.

You can do this using :

git commit --amend

from the command line, or look for an amend checkbox in the GUI you are using for git.

LeGEC
  • 46,477
  • 5
  • 57
  • 104