Skip to contentSkip to conversation

request: allow passing -X <strategy-option> to git checkout <path> to auto-solve merge conflicts

DISCUSSION Andrey Butirsky 2 participants 6 messages Dec 27, 2021 – Dec 29, 2021 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

Hi, stumbling upon this again and again, so decided to write finally,

while in conflicting state, the only thing we can do to auto-pick one or another side of conflict is passing --ours/--theirs option to git-checkout:
git checkout --ours/--theirs <path>

The problem is - it doesn't actually do a _merge_, i.e. you lose all non-conflicted changes.

There is no easy way to solve that currently without third-party tools.

This link illustrates it:
https://stackoverflow.com/a/68498101/1063363

Proposal:
Shell we add -X <strategy-option> to git checkout <path> to allow it do a merge and _actually solve_ merge conflicts? That would be in-pair with other commands taking the option already: git-merge, git-rebase, (etc.?)

#2 lore raw
In reply to a message not in the archive

Thanks Erik, please post your further replies to the mailing list so others could see it also.

On a topic,
I'm not familiar with Git code-base so don't know if it even possible in it's current architecture..

Quoted 25 lines · Erik Cervin Edin

That's my answer =)

I think adding a merge strategy option to checkout might be useful

Quoted 20 lines · Andrey Butirsky

Hi, stumbling upon this again and again, so decided to write finally,

while in conflicting state, the only thing we can do to auto-pick one or another side of conflict is passing --ours/--theirs option to git-checkout:
git checkout --ours/--theirs <path>

The problem is - it doesn't actually do a _merge_, i.e. you lose all non-conflicted changes.

There is no easy way to solve that currently without third-party tools.

This link illustrates it:
https://stackoverflow.com/a/68498101/1063363

Proposal:
Shell we add -X <strategy-option> to git checkout <path> to allow it do a merge and _actually solve_ merge conflicts?
That would be in-pair with other commands taking the option already:
git-merge, git-rebase, (etc.?)

#3 lore raw
Quoted 3 lines · Andrey Butirsky

Thanks Erik, please post your further replies to the mailing list so others could see it also.

Mea culpa

Quoted 3 lines

On a topic,
I'm not familiar with Git code-base so don't know if it even possible in it's current architecture..

It looks like
builtin/checkout.c checkout_merged
is responsible and calls
ll-merge.c ll_merge

I think other commands that allow merging strategies may use other "merge drivers".

From commit a944af1d86e6171d68ed2a3aa67b1d68f00e1fe8

Quoted 7 lines

merge: teach -Xours/-Xtheirs to binary ll-merge driver

The (discouraged) -Xours/-Xtheirs modes of merge are supposed to give a quick and dirty way to come up with a random mixture of cleanly merged parts and punted conflict resolution to take contents from one side in conflicting parts. These options however were only passed down to the low level merge driver for text.

It looks possible.
But perhaps the sentiment is that it's not adviceable?

#4 lore raw

On a tangent, you can set up your own merge tools.

So in git config you can add something like:

[mergetool "both"]
cmd = "sed -i -e '/^<<<<<<<$/d' -e '/^=======$/d' -e '/^>>>>>>>$/d' -- $MERGED"

and call it with git mergetool --tool=both

Quoted 30 lines · Erik Cervin Edin
Quoted 4 lines · Andrey Butirsky

Thanks Erik, please post your further replies to the mailing list so others could see it also.

Mea culpa

Quoted 3 lines

On a topic,
I'm not familiar with Git code-base so don't know if it even possible in it's current architecture..

It looks like
builtin/checkout.c checkout_merged
is responsible and calls
ll-merge.c ll_merge

I think other commands that allow merging strategies may use other "merge drivers".

From commit a944af1d86e6171d68ed2a3aa67b1d68f00e1fe8

Quoted 7 lines

merge: teach -Xours/-Xtheirs to binary ll-merge driver

The (discouraged) -Xours/-Xtheirs modes of merge are supposed to give a quick and dirty way to come up with a random mixture of cleanly merged parts and punted conflict resolution to take contents from one side in conflicting parts. These options however were only passed down to the low level merge driver for text.

It looks possible.
But perhaps the sentiment is that it's not adviceable?

#5 lore raw

This is exactly what I tried to avoid, since Git already seem has all the needed under the hood to prevent such disaster..

Quoted 8 lines · Erik Cervin Edin

On a tangent, you can set up your own merge tools.

So in git config you can add something like:

[mergetool "both"]
cmd = "sed -i -e '/^<<<<<<<$/d' -e '/^=======$/d' -e '/^>>>>>>>$/d' -- $MERGED"

and call it with git mergetool --tool=both

#6 lore raw
Quoted 3 lines · Andrey Butirsky

This is exactly what I tried to avoid, since Git already seem has all the needed under the hood to prevent such disaster..

It'd be neat if you could specify -X ours/theirs/both
But I'm not sure I would describe the current situation as disastrous