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

Re: Proper way to abort incorrect cherry-picking?

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Apr 28, 2010, 23:37 UTC
Message-ID
<20100428233758.GA1654@progeny.tock>
In-Reply-To
<o2j2cfc40321004281539j28fe44e0r5d029061e3e08b90@mail.gmail.com>
Hi Jon,
Jon Seymour wrote:
> If you use git reset --mixed HEAD@{1} you can reset the index to
> HEAD@{1} to reflect the pre-merge state.
The HEAD doesn’t advance in a failed merge, right?
[...]
> This is more complicated than it needs to be - if you had stashed (or
> committed) before cherry picking, things would be simpler.
If this were really necessary, I would consider it a bug.

I do think recovery is more complicated than it needs to be, since one has to check whether the merge/cherry-pick failed before cancelling it. There are three cases.

 - If an early check prevented the operation (message with “fatal:”,
   status = 128), then the index and work tree were not touched.
   No recovery required.
 - If there were conflicts (message with “Conflicts:”, status = 1),
   the index will record the competing versions of conflicted files,
   and the work tree will represent the situation with conflict
   markers.
   Use ‘git reset --merge’ to recover.
 - If the merge proceeded cleanly (status = 0), but it was a bad
   idea after all, the index and work tree record the new version now.
   Use ‘git reset --keep HEAD@{1}’ to undo the operation.

Have fun, Jonathan

Previous: Jon SeymourNext: Jon Seymour
Message 5 of 14 in “Proper way to abort incorrect cherry-picking?”
  1. Eugene SajineApr 28, 2010
  2. David BorowitzApr 28, 2010
  3. Eugene SajineApr 28, 2010
  4. Jon SeymourApr 28, 2010
  5. Jonathan NiederApr 28, 2010
  6. Jon SeymourApr 29, 2010
  7. git cherry(pick) dumps coreAndreas Krey, Apr 29, 2010
  8. Jonathan NiederApr 29, 2010
  9. Andreas KreyApr 29, 2010
  10. Jonathan NiederApr 30, 2010
  11. cherry-pick: do not dump core when iconv failsJonathan Nieder, May 8, 2010
  12. Junio C HamanoMay 8, 2010
  13. Jonathan NiederApr 28, 2010
  14. Eugene SajineApr 28, 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.