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

Re: Thoughts about the -m option of cherry-pick and revert

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Jun 21, 2024, 10:19 UTC
Message-ID
<6e71b1f3-599f-49c3-be37-e499f28983cf@gmail.com>
In-Reply-To
<dd58a60d-a551-4726-85a7-f47b851914be@haller-berlin.de>
On 21/06/2024 07:33, Stefan Haller wrote:
> On 21.06.24 04:03, Junio C Hamano wrote:
>> Stefan Haller <lists@haller-berlin.de> writes:
 >
Show 16 quoted lines
> Hm, in all example scenarios I experimented with, picking the wrong
> parent would result in an empty diff, and consequently an error message
> like this:
> 
>     nothing to commit, working tree clean
>     The previous cherry-pick is now empty, possibly due to conflict
>     resolution.
>     If you wish to commit it anyway, use:
> 
>         git commit --allow-empty
> 
>     Otherwise, please use 'git cherry-pick --skip'
> 
> I'm not sure if this error is easier or harder to understand than the
> one you get today when omitting -m, but we could probably improve it by
> mentioning the -m option if the cherry-picked commit was a merge.

That might be helpful - if we do that we'd want to make sure that the user can retry this pick with "-m" without restarting the whole cherry-pick.

> I'd be interested in example scenarios where both sides of the merge
> have non-empty diffs. Won't this only happen for evil merges?

I think you'd need a conflicting merge that is resolved in a way that the resolution of the conflicting lines doesn't match either parent. (I assume that's what you mean by evil but I thought it best to check)

Show 9 quoted lines
>> If I were simplifying this, I would probably
>>
>>   (1) disallow cherry-picking a merge (and suggest redoing the same
>>       merge, possibly after rebasing the copy of the merged history
>>       to an appropriate base as needed), and
> 
> This seems unnecessarily restrictive to me. Cherry-picking merge commits
> using -m1 is useful, it's an important part of our release workflow at
> my day job.

I can see why people want to revert merges but cherry-picking them always feels strange to me - what is the advantage over actually merging the branch and seeing the full history of that commit?

Show 5 quoted lines
>>   (2) allowing reverting a merge only wrt the first parent,
> 
> Interesting, that's what I'm considering doing in lazygit (except for
> both revert and cherry-pick), but I kind of didn't expect much support
> for that idea. :-)

For lazygit I would think it would be fine to be a bit more restrictive that git as anyone with an unusual requirement can always fall back to using git for that.

Best Wishes
Phillip
> -Stefan
> 
Previous: Stefan HallerNext: Stefan Haller
Message 4 of 9 in “Thoughts about the -m option of cherry-pick and revert”
  1. Stefan HallerJun 20, 2024
  2. Junio C HamanoJun 21, 2024
  3. Stefan HallerJun 21, 2024
  4. Phillip WoodJun 21, 2024
  5. Stefan HallerJun 21, 2024
  6. Junio C HamanoJun 21, 2024
  7. Stefan HallerJun 24, 2024
  8. Junio C HamanoJun 24, 2024
  9. Phillip WoodJun 21, 2024

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.