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

Re: Cherry-Pick without affecting working tree / index?

From
Elijah Newren <newren@gmail.com>
Date
Jun 2, 2022, 23:52 UTC
Message-ID
<CABPp-BF4kD8uieZ1QWLbzejhuhaZA7rYfDR+8dGrteL_4UhkHQ@mail.gmail.com>
In-Reply-To
<CAPMMpoj8CyhB=g0=HD2Y2w6+mkGVRsgoq6zsb5XCTt95uDELog@mail.gmail.com>
On Thu, Jun 2, 2022 at 10:08 AM Tao Klerks <tao@klerks.biz> wrote:
Show 24 quoted lines
>
> Hi folks,
>
> I'm wondering whether it's possible to perform a (non-conflicting)
> cherry pick without impacting the working tree (or index).
>
> I understand Elijah Newren has been working on git-merge-tree changes
> that would allow for simulating (and even saving) merge commits
> without affecting the index or working tree, and I could imagine
> that's a piece of how such a thing could/should work, but I'm not
> terribly clear on the relationship between merges and cherry-picks.
>
> It *seems* as though I could enact something functionally equivalent
> to a cherry-pick by first creating a (temporary) "--ours" merge commit
> on the target branch, pretending to have merged the parent commit of
> the cherry-pickable one, and then merging the cherry-pick commit
> itself on top of that. The resulting tree could be used as the basis
> for a final commit on top of the original tip of the target branch, if
> that merge were clean, and otherwise fail saying "there are conflicts,
> go do things properly in a working tree pls".
>
> I'm not sure whether this is the right way to conceive of
> cherry-picking, however, or whether it makes more sense to conceive of
> it as a single-commit rebase.

The merge --ours stuff is going down a weird path that I don't recommend, but thinking of it as a single-commit rebase is good. In fact, the default rebase backend was originally written by calling cherry-pick for each commit in question.

> Is there a relationship between
> git-merge-tree and rebases?

The patches I submitted do not have the ability for rebases to be built from git-merge-tree. There's a debate over whether my series should be tweaked to enable it. Peruse the thread over at https://lore.kernel.org/git/xmqqh78nj0q0.fsf@gitster.g/ if you want to read some of the discussion, as well as see discussion of how merging and cherry-picks/rebases are related.

> Is there an aspiration to develop "server
> side rebase" also at some stage?

Yes, already in progress and possibly usable for simple cases. Haven't had some time to work on it for a while (~4 months, sigh), but will definitely get some time in late June/early July to carry it on. You can check out the "replay" branch of github.com/newren/git if you're curious.

Previous: Tao KlerksNext: Tao Klerks
Message 2 of 3 in “Cherry-Pick without affecting working tree / index?”
  1. Tao KlerksJun 2, 2022
  2. Elijah NewrenJun 2, 2022
  3. Tao KlerksJun 3, 2022

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.