threads / discuss / 60884

Interactive rebase: using "pick" for merge commits

Subject: Interactive rebase: using "pick" for merge commits

## tl;dr

10 messages between Feb 9, 2024 and Feb 27, 2024.

replies: 9people: 4as markdown or json

Stefan Haller· Feb 9, 2024, 15:52 UTC · lore

When I do an interactive rebase, and manually enter a "pick" with the commit hash of a merge commit, I get the following confusing error message:

error: commit fa1afe1 is a merge but no -m option was given. hint: Could not execute the todo command hint: hint: pick fa1afe1 some subject hint: hint: It has been rescheduled; [rest of message snipped]

This error message makes it sound like I could somehow add "-m1" after the "pick" to make it work (which is actually what I would like to be able to do). I had to go read the source code to find out that that's not the case, and the error message only comes from the fact that the code is shared with the cherry-pick and revert commands, which do have the -m option.

Is it crazy to want pick to work like this? Should it be supported?
-Stefan
Phillip Wood· Feb 9, 2024, 16:24 UTC · re: Stefan Haller · lore

Re: Interactive rebase: using "pick" for merge commits

Hi Stefan
On 09/02/2024 15:52, Stefan Haller wrote:
Show 16 quoted lines
> When I do an interactive rebase, and manually enter a "pick" with the
> commit hash of a merge commit, I get the following confusing error message:
> 
> error: commit fa1afe1 is a merge but no -m option was given.
> hint: Could not execute the todo command
> hint:
> hint:     pick fa1afe1 some subject
> hint:
> hint: It has been rescheduled; [rest of message snipped]
> 
> This error message makes it sound like I could somehow add "-m1" after
> the "pick" to make it work (which is actually what I would like to be
> able to do). I had to go read the source code to find out that that's
> not the case, and the error message only comes from the fact that the
> code is shared with the cherry-pick and revert commands, which do have
> the -m option.

Oh, that's unfortunate - we should really reject the todo list when we parse it at the start of the rebase if it is going to try and "pick" a merge.

> Is it crazy to want pick to work like this? Should it be supported?

It causes problems trying to maintain the topology. In the past there was a "--preserve-merges" option that allowed one to "pick" merges but it broke if the user edited the todo list. The "--rebase-merges" option was introduced with the "label", "reset" and "merge" todo list instructions to allow the user to control the topology.

Best Wishes
Phillip
Stefan Haller· Feb 10, 2024, 09:23 UTC · re: Phillip Wood · lore

Re: Interactive rebase: using "pick" for merge commits

On 09.02.24 17:24, Phillip Wood wrote:
Show 14 quoted lines
> On 09/02/2024 15:52, Stefan Haller wrote:
>> When I do an interactive rebase, and manually enter a "pick" with the
>> commit hash of a merge commit, I get the following confusing error
>> message:
>>
>> error: commit fa1afe1 is a merge but no -m option was given.
>> 
>> Is it crazy to want pick to work like this? Should it be supported?
> 
> It causes problems trying to maintain the topology. In the past there
> was a "--preserve-merges" option that allowed one to "pick" merges but
> it broke if the user edited the todo list. The "--rebase-merges" option
> was introduced with the "label", "reset" and "merge" todo list
> instructions to allow the user to control the topology.

Yes, I'm familiar with all this, but that's not what I mean. I don't want to maintain the topology here, and I'm also not suggesting that git itself generates such "pick" entries with -mX arguments (maybe I wasn't clear on that). What I want to do is to add such entries myself, as a user, resulting in the equivalent of doing a "break" at that point in the rebase and doing a "git cherry-pick -mX <hash-of-merge-commit>" manually.

-Stefan
Patrick Steinhardt· Feb 12, 2024, 07:15 UTC · re: Stefan Haller · lore

Re: Interactive rebase: using "pick" for merge commits

On Sat, Feb 10, 2024 at 10:23:16AM +0100, Stefan Haller wrote:
Show 23 quoted lines
> On 09.02.24 17:24, Phillip Wood wrote:
> > On 09/02/2024 15:52, Stefan Haller wrote:
> >> When I do an interactive rebase, and manually enter a "pick" with the
> >> commit hash of a merge commit, I get the following confusing error
> >> message:
> >>
> >> error: commit fa1afe1 is a merge but no -m option was given.
> >> 
> >> Is it crazy to want pick to work like this? Should it be supported?
> > 
> > It causes problems trying to maintain the topology. In the past there
> > was a "--preserve-merges" option that allowed one to "pick" merges but
> > it broke if the user edited the todo list. The "--rebase-merges" option
> > was introduced with the "label", "reset" and "merge" todo list
> > instructions to allow the user to control the topology.
> 
> Yes, I'm familiar with all this, but that's not what I mean. I don't
> want to maintain the topology here, and I'm also not suggesting that git
> itself generates such "pick" entries with -mX arguments (maybe I wasn't
> clear on that). What I want to do is to add such entries myself, as a
> user, resulting in the equivalent of doing a "break" at that point in
> the rebase and doing a "git cherry-pick -mX <hash-of-merge-commit>"
> manually.

It would be neat indeed if this could be specified in the instruction sheet. We already support options for the "merge" instruction, so extending "pick" to support options isn't that far-fetched. Then it would become possible to say "pick -m1 fa1afe1".

Patrick
Phillip Wood· Feb 12, 2024, 14:38 UTC · re: Patrick Steinhardt · lore

Re: Interactive rebase: using "pick" for merge commits

Hi Patrick and Stefan
On 12/02/2024 07:15, Patrick Steinhardt wrote:
Show 14 quoted lines
> On Sat, Feb 10, 2024 at 10:23:16AM +0100, Stefan Haller wrote:
>> On 09.02.24 17:24, Phillip Wood wrote:
>> Yes, I'm familiar with all this, but that's not what I mean. I don't
>> want to maintain the topology here, and I'm also not suggesting that git
>> itself generates such "pick" entries with -mX arguments (maybe I wasn't
>> clear on that). What I want to do is to add such entries myself, as a
>> user, resulting in the equivalent of doing a "break" at that point in
>> the rebase and doing a "git cherry-pick -mX <hash-of-merge-commit>"
>> manually.
> 
> It would be neat indeed if this could be specified in the instruction
> sheet. We already support options for the "merge" instruction, so
> extending "pick" to support options isn't that far-fetched. Then it
> would become possible to say "pick -m1 fa1afe1".

It would certainly be possible to extend the sequencer to do that but I'm not familiar with why people use "git cherry-pick -m" [1] so I'm wondering what this would be used for. It would involve a bit of extra complexity so I think we'd want a compelling reason as to why cherry-picking merges without maintaining the topology is useful especially as one can currently do that via "exec git cherry-pick -m ..."

Best Wishes
Phillip

[1] I did a quick web search and the results all seemed to focus on how to do it rather than why you'd want to.

Stefan Haller· Feb 23, 2024, 20:59 UTC · re: Phillip Wood · lore

Re: Interactive rebase: using "pick" for merge commits

On 12.02.24 15:38, Phillip Wood wrote:
Show 24 quoted lines
> Hi Patrick and Stefan
> 
> On 12/02/2024 07:15, Patrick Steinhardt wrote:
>> On Sat, Feb 10, 2024 at 10:23:16AM +0100, Stefan Haller wrote:
>>> On 09.02.24 17:24, Phillip Wood wrote:
>>> Yes, I'm familiar with all this, but that's not what I mean. I don't
>>> want to maintain the topology here, and I'm also not suggesting that git
>>> itself generates such "pick" entries with -mX arguments (maybe I wasn't
>>> clear on that). What I want to do is to add such entries myself, as a
>>> user, resulting in the equivalent of doing a "break" at that point in
>>> the rebase and doing a "git cherry-pick -mX <hash-of-merge-commit>"
>>> manually.
>>
>> It would be neat indeed if this could be specified in the instruction
>> sheet. We already support options for the "merge" instruction, so
>> extending "pick" to support options isn't that far-fetched. Then it
>> would become possible to say "pick -m1 fa1afe1".
> 
> It would certainly be possible to extend the sequencer to do that but
> I'm not familiar with why people use "git cherry-pick -m" [1] so I'm
> wondering what this would be used for. It would involve a bit of extra
> complexity so I think we'd want a compelling reason as to why
> cherry-picking merges without maintaining the topology is useful
> especially as one can currently do that via "exec git cherry-pick -m ..."

Ok, I suppose the answer will probably not count as a compelling reason. My reason for wanting this is that lazygit currently implements cherry-picking in terms of an interactive rebase, rather then calling git-cherry-pick. And the reason why it does this is that when you cherry-pick multiple commits, and one of them conflicts, then you get lazygit's nice visualization of the rebase todo list to show you where in the sequence you are, what the conflicting commit is, how many are left etc. It just happens to support this well for .git/rebase-merge/git-rebase-todo, but not for .git/sequencer/todo.

It probably makes more sense to teach lazygit to visualize the .git/sequencer/todo file, and then use git cherry-pick.

See https://github.com/jesseduffield/lazygit/issues/3317
-Stefan
Phillip Wood· Feb 26, 2024, 10:56 UTC · re: Stefan Haller · lore

Re: Interactive rebase: using "pick" for merge commits

Hi Stefan
On 23/02/2024 20:59, Stefan Haller wrote:
> On 12.02.24 15:38, Phillip Wood wrote:
>> Hi Patrick and Stefan
 >>
Show 16 quoted lines
>> It would certainly be possible to extend the sequencer to do that but
>> I'm not familiar with why people use "git cherry-pick -m" [1] so I'm
>> wondering what this would be used for. It would involve a bit of extra
>> complexity so I think we'd want a compelling reason as to why
>> cherry-picking merges without maintaining the topology is useful
>> especially as one can currently do that via "exec git cherry-pick -m ..."
> 
> Ok, I suppose the answer will probably not count as a compelling reason.
> My reason for wanting this is that lazygit currently implements
> cherry-picking in terms of an interactive rebase, rather then calling
> git-cherry-pick. And the reason why it does this is that when you
> cherry-pick multiple commits, and one of them conflicts, then you get
> lazygit's nice visualization of the rebase todo list to show you where
> in the sequence you are, what the conflicting commit is, how many are
> left etc. It just happens to support this well for
> .git/rebase-merge/git-rebase-todo, but not for .git/sequencer/todo.

Thanks for the context. I can see how that is convenient for lazygit (and makes we think that perhaps we should teach "git status" to show pending cherry-picks) but I'm afraid I don't think that is a good reason for adding the ability to pick merges to git rebase.

> It probably makes more sense to teach lazygit to visualize the
> .git/sequencer/todo file, and then use git cherry-pick.

If lazygit is generating the todo list for the cherry-pick could it check if the commit is a merge and insert "exec cherry-pick -m ..." for those commits? The UI could detect that and display something more user friendly for those lines in the todo list. It is still more work for lazygit but perhaps less than supporting cherry-picks directly.

Best Wishes
Phillip
Stefan Haller· Feb 26, 2024, 19:07 UTC · re: Phillip Wood · lore

Re: Interactive rebase: using "pick" for merge commits

On 26.02.24 11:56, Phillip Wood wrote:
Show 6 quoted lines
>> It probably makes more sense to teach lazygit to visualize the
>> .git/sequencer/todo file, and then use git cherry-pick.
> 
> If lazygit is generating the todo list for the cherry-pick could it
> check if the commit is a merge and insert "exec cherry-pick -m ..." for
> those commits?

That's a good idea, but it wouldn't buy us very much. We'd still have to add support for conflicts during a cherry-pick; when there's a conflict during a rebase, lazygit has this nice visualization of the conflicting commit (we talked about that in [1], and it turned out to be working extremely well), so it would have to learn to do the same thing for a conflicting cherry-pick (although this does seem to be a lot easier). And then it would have to learn to call "cherry-pick --continue" rather than "rebase --continue" after resolving. But if we do all these things, then we're not so far away from being able to just call git cherry-pick ourselves.

-Stefan
[1] <https://public-inbox.org/git/
     961e68d7-5f43-c385-10fa-455b8e2f32d0@haller-berlin.de/>
phillip.wood123@gmail.com· Feb 27, 2024, 10:41 UTC · re: Stefan Haller · lore

Re: Interactive rebase: using "pick" for merge commits

On 26/02/2024 19:07, Stefan Haller wrote:
Show 18 quoted lines
> On 26.02.24 11:56, Phillip Wood wrote:
>>> It probably makes more sense to teach lazygit to visualize the
>>> .git/sequencer/todo file, and then use git cherry-pick.
>>
>> If lazygit is generating the todo list for the cherry-pick could it
>> check if the commit is a merge and insert "exec cherry-pick -m ..." for
>> those commits?
> 
> That's a good idea, but it wouldn't buy us very much. We'd still have to
> add support for conflicts during a cherry-pick; when there's a conflict
> during a rebase, lazygit has this nice visualization of the conflicting
> commit (we talked about that in [1], and it turned out to be working
> extremely well), so it would have to learn to do the same thing for a
> conflicting cherry-pick (although this does seem to be a lot easier).
> And then it would have to learn to call "cherry-pick --continue" rather
> than "rebase --continue" after resolving. But if we do all these things,
> then we're not so far away from being able to just call git cherry-pick
> ourselves.

Oh I'd forgotten about handling conflicts - that does make my proposal less attractive.

Best Wishes
Phillip
> -Stefan
> 
> [1] <https://public-inbox.org/git/
>       961e68d7-5f43-c385-10fa-455b8e2f32d0@haller-berlin.de/>
Junio C Hamano· Feb 12, 2024, 16:39 UTC · re: Patrick Steinhardt · lore

Re: Interactive rebase: using "pick" for merge commits

Patrick Steinhardt <ps@pks.im> writes:
Show 29 quoted lines
> On Sat, Feb 10, 2024 at 10:23:16AM +0100, Stefan Haller wrote:
>> On 09.02.24 17:24, Phillip Wood wrote:
>> > On 09/02/2024 15:52, Stefan Haller wrote:
>> >> When I do an interactive rebase, and manually enter a "pick" with the
>> >> commit hash of a merge commit, I get the following confusing error
>> >> message:
>> >>
>> >> error: commit fa1afe1 is a merge but no -m option was given.
>> >> 
>> >> Is it crazy to want pick to work like this? Should it be supported?
>> > 
>> > It causes problems trying to maintain the topology. In the past there
>> > was a "--preserve-merges" option that allowed one to "pick" merges but
>> > it broke if the user edited the todo list. The "--rebase-merges" option
>> > was introduced with the "label", "reset" and "merge" todo list
>> > instructions to allow the user to control the topology.
>> 
>> Yes, I'm familiar with all this, but that's not what I mean. I don't
>> want to maintain the topology here, and I'm also not suggesting that git
>> itself generates such "pick" entries with -mX arguments (maybe I wasn't
>> clear on that). What I want to do is to add such entries myself, as a
>> user, resulting in the equivalent of doing a "break" at that point in
>> the rebase and doing a "git cherry-pick -mX <hash-of-merge-commit>"
>> manually.
>
> It would be neat indeed if this could be specified in the instruction
> sheet. We already support options for the "merge" instruction, so
> extending "pick" to support options isn't that far-fetched. Then it
> would become possible to say "pick -m1 fa1afe1".
Would adding "x git cherry-pick -m 1 $that_one" work there?

← back to recent threads