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

6 messages from 2021-12-27 to 2021-12-29. Participants: Andrey Butirsky, Erik Cervin Edin.
Thread: https://gitlist.dev/t/57153

## Andrey Butirsky, 2021-12-27 12:52

Subject: request: allow passing -X <strategy-option> to git checkout <path> to auto-solve merge conflicts
Message-ID: <3e1548ab-5e20-9555-bd10-d6cbf2ffbce4@gmail.com>
URL: https://gitlist.dev/e/3e1548ab-5e20-9555-bd10-d6cbf2ffbce4%40gmail.com

```
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.?)


```

## Andrey Butirsky, 2021-12-28 20:44

Subject: Re: request: allow passing -X <strategy-option> to git checkout <path> to auto-solve merge conflicts
Message-ID: <a8f3246f-2b50-e713-16c3-1d23b80a42a1@gmail.com>
URL: https://gitlist.dev/e/a8f3246f-2b50-e713-16c3-1d23b80a42a1%40gmail.com
In-Reply-To: <CA+JQ7M-By65FVPnMFnwE8zx3T4O7DV3_5Kf2P6eZhP4Zcemorg@mail.gmail.com>

```
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..


On 28.12.2021 20:32, Erik Cervin Edin wrote:
> That's my answer =)
>
> I think adding a merge strategy option to checkout might be useful
>
> On Mon, Dec 27, 2021 at 4:49 PM Andrey Butirsky <butirsky@gmail.com> wrote:
>> 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.?)
>>

```

## Erik Cervin Edin, 2021-12-28 21:50

Subject: Re: request: allow passing -X <strategy-option> to git checkout <path> to auto-solve merge conflicts
Message-ID: <CA+JQ7M9Ht5vSfDDEuYyK7pBPBvgjzi7L6jEYX8dkP4PMFK-M2Q@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BJQ7M9Ht5vSfDDEuYyK7pBPBvgjzi7L6jEYX8dkP4PMFK-M2Q%40mail.gmail.com
In-Reply-To: <a8f3246f-2b50-e713-16c3-1d23b80a42a1@gmail.com>

```
> On Tue, Dec 28, 2021 at 9:44 PM Andrey Butirsky <butirsky@gmail.com> wrote:
> Thanks Erik, please post your further replies to the mailing list so
> others could see it also.

Mea culpa

> 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
> 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?

```

## Erik Cervin Edin, 2021-12-29 12:13

Subject: Re: request: allow passing -X <strategy-option> to git checkout <path> to auto-solve merge conflicts
Message-ID: <CA+JQ7M-gornjkB78Dgx-bHW7Ps=C2936vDNUakQ-VG8KAyZ=YA@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BJQ7M-gornjkB78Dgx-bHW7Ps%3DC2936vDNUakQ-VG8KAyZ%3DYA%40mail.gmail.com
In-Reply-To: <CA+JQ7M9Ht5vSfDDEuYyK7pBPBvgjzi7L6jEYX8dkP4PMFK-M2Q@mail.gmail.com>

```
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

On Tue, Dec 28, 2021 at 10:50 PM Erik Cervin Edin <erik@cervined.in> wrote:
>
> > On Tue, Dec 28, 2021 at 9:44 PM Andrey Butirsky <butirsky@gmail.com> wrote:
> > Thanks Erik, please post your further replies to the mailing list so
> > others could see it also.
>
> Mea culpa
>
> > 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
> > 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?

```

## Andrey Butirsky, 2021-12-29 13:35

Subject: Re: request: allow passing -X <strategy-option> to git checkout <path> to auto-solve merge conflicts
Message-ID: <fffeed2f-c956-d34f-ea5f-73f52e2d2be4@gmail.com>
URL: https://gitlist.dev/e/fffeed2f-c956-d34f-ea5f-73f52e2d2be4%40gmail.com
In-Reply-To: <CA+JQ7M-gornjkB78Dgx-bHW7Ps=C2936vDNUakQ-VG8KAyZ=YA@mail.gmail.com>

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

On 29.12.2021 15:13, Erik Cervin Edin wrote:
> 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

```

## Erik Cervin Edin, 2021-12-29 14:51

Subject: Re: request: allow passing -X <strategy-option> to git checkout <path> to auto-solve merge conflicts
Message-ID: <CA+JQ7M9ANzeiZC7uLPoe671hT8wGDyO7tWu7+YxfDB0QE6YR5Q@mail.gmail.com>
URL: https://gitlist.dev/e/CA%2BJQ7M9ANzeiZC7uLPoe671hT8wGDyO7tWu7%2BYxfDB0QE6YR5Q%40mail.gmail.com
In-Reply-To: <fffeed2f-c956-d34f-ea5f-73f52e2d2be4@gmail.com>

```
On Wed, Dec 29, 2021 at 2:35 PM Andrey Butirsky <butirsky@gmail.com> wrote:
>
> 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

```
