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

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

From
SHStefan Haller <lists@haller-berlin.de>
Date
Jun 20, 2024, 10:05 UTC
Message-ID
<e60a8b1a-98c8-4ac7-b966-ff9635bb781d@haller-berlin.de>

There are plenty of StackOverflow questions and blog posts about the error message that you get when you use git cherry-pick or git revert on a merge commit without specifying the -m option. Many people don't seem to understand what the error message means, or why they even get an error in the first place.

The answers to these questions patiently explain what the error means and why the -m option is necessary. Many of them contain example scenarios; but I haven't seen a single one that doesn't use -m1 to illustrate the usage.

I have two questions:
- What are real-world scenarios where you would use a mainline number
  other than 1? I could only come up with a single example myself, which
  is that you have a topic branch, and right before merging it back to
  main, you merge main into the topic branch; and then you merge it to
  main with a fast-forward merge. If you then want to cherry-pick or
  revert that topic, you'd have to use -m2 on that last merge from main.
  Any other examples?
- Wouldn't it make sense to default to -m1 when no -m option is given?
  It seems that this would do the expected thing in the vast majority of
  cases.

For the GUI client that I'm co-maintaining (lazygit), I'm actually considering going so far as to not providing a choice at all, and always using -m1. I'm not fully decided yet if that's a good idea, but it seems that most people expect this, most of the time.

I'm probably missing something though, but what?
-Stefan
Next: Junio C Hamano
Message 1 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.