git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] cherry-pick: Add an option to prepend a string to the commit message

From
Bobby Powers <bobbypowers@gmail.com>
Date
Jun 12, 2010, 06:43 UTC
Message-ID
<4C132C7E.5090606@gmail.com>
In-Reply-To
<20100612062812.GA12685@coredump.intra.peff.net>
On 06/11/2010 11:28 PM, Jeff King wrote:
Show 12 quoted lines
> On Sat, Jun 12, 2010 at 12:58:32AM -0500, Jonathan Nieder wrote:
>
>> I would be interested to hear from those who might know whether
>> something generic like the applypatch-msg hook could work (which is
>> not to say a convenient command-line option would not be handy to have
>> in addition to that.)
>
> What bothers me is how specific this munging is. What if I want to
> append to the message? Or put something after the subject line, but
> before the commit body? Or add a pseudo-header (like signed-off-by) to
> the set of pseudo-headers at the end, properly adding a newline if it is
> the first such pseudo-header.

What prompted this was a large project I had checked out through git-svn. I had made a number of commits to trunk, interspersed with other dev's work. I needed to cherry-pick my work into a stable branch, but each commit needed to start with 'cherry-pick rXXX:', where XXX was the subversion commit number.

My solution was the following:
$ git checkout $RELEASE_BRANCH
$ export WHAT="my-subsystem:"
$ export SINCE="Jun 1 2010"
$ for i in `git log --grep="$WHAT" --oneline master --after="$SINCE" \
             | cut -d ' ' -f 1 | tac`;                                \
       do git cherry-pick $i -x                                       \
              --prepend "cherry pick r$(echo $(git log -1 $i) | perl  \
                                   -pe 's|.*/trunk@(\d+).*|\1|'): ";  \
   done

but, as you point out, I could have accomplished the same thing through other means.

Show 16 quoted lines
> FWIW, we can already do this kind of stuff with:
>
>    GIT_EDITOR="sed -i 1i$prefix" git cherry-pick -e $ref
>
> or
>
>    git cherry-pick -n $ref&&
>    sed -i 1i$prefix .git/MERGE_MSG
>    GIT_EDITOR=true git commit
>
> I'll admit the first one is not very intuitive. But it is easy to script
> around the second form. For one of my examples, I would probably do:
>
>    git cherry-pick -n $ref&&
>    git log -1 --format='%s%n%ncontent between subject and body%n%b' |
>    git commit -F -

I like this; it clearly hadn't occurred to me. I can just use this format instead.

yours, Bobby

Show 9 quoted lines
> The specifics aren't important, but I think you can see that the "don't
> commit automatically, make a message as you like, and then use the
> regular message-specifiers for commit to commit it" technique is pretty
> straightforward and very flexible.
>
> It's obviously more typing for occasional interactive use, but in that
> case, why not just use "git cherry-pick -e" and use your editor?
>
> -Peff
Previous: Jeff KingNext: Jonathan Nieder
Message 5 of 9 in “cherry-pick: Add an option to prepend a string to the commit message”
  1. cherry-pick: Add an option to prepend a string to the commit messageBobby Powers, Jun 12, 2010
  2. Jonathan NiederJun 12, 2010
  3. Junio C HamanoJun 12, 2010
  4. Jeff KingJun 12, 2010
  5. Bobby PowersJun 12, 2010
  6. Jonathan NiederJun 12, 2010
  7. Jeff KingJun 12, 2010
  8. Junio C HamanoJun 14, 2010
  9. Junio C HamanoJun 14, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.