threads / discuss / 62414

2.43+ git checkout --theirs on stash error - no alternative?

Subject: 2.43+ git checkout --theirs on stash error - no alternative?

## tl;dr

6 messages between Oct 27, 2024 and Nov 6, 2024.

replies: 5people: 3as markdown or json

Devste Devste· Oct 27, 2024, 22:16 UTC · lore

What did you do before the bug happened? (Steps to reproduce your issue) git checkout 'stash@{0}' --theirs -- "some-file.txt"

What did you expect to happen? (Expected behavior) Checking out the file exactly as it is in the stash with any conflicts resolved using the stash's data

What happened instead? (Actual behavior) fatal: '--merge', '--ours', or '--theirs' cannot be used when checking out of a tree

What's different between what you expected and what actually happened? Error and unresolved conflicts

Anything else you want to add: This behavior was changed in 2.43 https://www.spinics.net/lists/git/msg463600.html However, I think this change is wrong. Since using --theirs still makes sense, if you want to restore a file to the exact state it was in the stash. While the change probably had in mind that this should be used: git cherry-pick --no-commit --mainline 1 --strategy-option=theirs 'stash@{0}' This leads to different results than git checkout --theirs, since it tries to resolve the conflicts and is not correctly using "theirs" to automatically resolve them How can the pre 2.43 behavior be achieved?

Please review the rest of the bug report below. You can delete any lines you don't wish to share.

[System Info] git version: git version 2.43.5 cpu: x86_64 no commit associated with this build sizeof-long: 8 sizeof-size_t: 8 shell-path: /bin/sh uname: Linux 5.14.0-162.23.1.el9_1.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Apr 11 19:09:37 UTC 2023 x86_64 compiler info: gnuc: 11.4 libc info: glibc: 2.34 $SHELL (typically, interactive shell): /bin/bash

[Enabled Hooks]
Devste Devste· Oct 27, 2024, 22:31 UTC · re: Devste Devste · lore

Re: 2.43+ git checkout --theirs on stash error - no alternative?

Turns out the previous behavior can be achieved with git restore --source='stash@{0}' -- "some-file.txt"

On Sun, 27 Oct 2024 at 23:16, Devste Devste <devstemail@gmail.com> wrote:
Show 49 quoted lines
>
> What did you do before the bug happened? (Steps to reproduce your issue)
> git checkout 'stash@{0}' --theirs -- "some-file.txt"
>
> What did you expect to happen? (Expected behavior)
> Checking out the file exactly as it is in the stash with any conflicts
> resolved using the stash's data
>
> What happened instead? (Actual behavior)
> fatal: '--merge', '--ours', or '--theirs' cannot be used when checking
> out of a tree
>
> What's different between what you expected and what actually happened?
> Error and unresolved conflicts
>
> Anything else you want to add:
> This behavior was changed in 2.43
> https://www.spinics.net/lists/git/msg463600.html
> However, I think this change is wrong. Since using --theirs still
> makes sense, if you want to restore a file to the exact state it was
> in the stash.
> While the change probably had in mind that this should be used: git
> cherry-pick --no-commit --mainline 1 --strategy-option=theirs
> 'stash@{0}'
> This leads to different results than git checkout --theirs, since it
> tries to resolve the conflicts and is not correctly using "theirs" to
> automatically resolve them
> How can the pre 2.43 behavior be achieved?
>
> Please review the rest of the bug report below.
> You can delete any lines you don't wish to share.
>
>
> [System Info]
> git version:
> git version 2.43.5
> cpu: x86_64
> no commit associated with this build
> sizeof-long: 8
> sizeof-size_t: 8
> shell-path: /bin/sh
> uname: Linux 5.14.0-162.23.1.el9_1.x86_64 #1 SMP PREEMPT_DYNAMIC Tue
> Apr 11 19:09:37 UTC 2023 x86_64
> compiler info: gnuc: 11.4
> libc info: glibc: 2.34
> $SHELL (typically, interactive shell): /bin/bash
>
>
> [Enabled Hooks]
Taylor Blau· Oct 27, 2024, 23:38 UTC · re: Devste Devste · lore

Re: 2.43+ git checkout --theirs on stash error - no alternative?

On Sun, Oct 27, 2024 at 11:31:05PM +0100, Devste Devste wrote:
> Turns out the previous behavior can be achieved with
> git restore --source='stash@{0}' -- "some-file.txt"

Hmm. What you wrote above here makes sense, but I agree with the original change from Junio (CC'd) that using `--theirs` does not make sense when the source is a tree-ish and not the index directly.

This is different, though, since here you are just trying to check out the contents of some-file.txt at stash@{0}, without `--theirs`. What did you mean in the previous example, and why was `--theirs` necessary in the call there?

Thanks, Taylor

Devste Devste· Nov 4, 2024, 10:09 UTC · re: Taylor Blau · lore

Re: 2.43+ git checkout --theirs on stash error - no alternative?

"--theirs" was necessary since I want the file exactly as it is in the stash - any conflicts from applying the file from stash should be automatically resolved using the hunk from the stash

On Mon, 28 Oct 2024 at 00:38, Taylor Blau <me@ttaylorr.com> wrote:
Show 16 quoted lines
>
> On Sun, Oct 27, 2024 at 11:31:05PM +0100, Devste Devste wrote:
> > Turns out the previous behavior can be achieved with
> > git restore --source='stash@{0}' -- "some-file.txt"
>
> Hmm. What you wrote above here makes sense, but I agree with the
> original change from Junio (CC'd) that using `--theirs` does not make
> sense when the source is a tree-ish and not the index directly.
>
> This is different, though, since here you are just trying to check out
> the contents of some-file.txt at stash@{0}, without `--theirs`. What did
> you mean in the previous example, and why was `--theirs` necessary in
> the call there?
>
> Thanks,
> Taylor
Junio C Hamano· Nov 4, 2024, 10:17 UTC · re: Devste Devste · lore

Re: 2.43+ git checkout --theirs on stash error - no alternative?

Devste Devste <devstemail@gmail.com> writes:
Show 14 quoted lines
> On Mon, 28 Oct 2024 at 00:38, Taylor Blau <me@ttaylorr.com> wrote:
>>
>> On Sun, Oct 27, 2024 at 11:31:05PM +0100, Devste Devste wrote:
>> > Turns out the previous behavior can be achieved with
>> > git restore --source='stash@{0}' -- "some-file.txt"
>>
>> Hmm. What you wrote above here makes sense, but I agree with the
>> original change from Junio (CC'd) that using `--theirs` does not make
>> sense when the source is a tree-ish and not the index directly.
>>
>> This is different, though, since here you are just trying to check out
>> the contents of some-file.txt at stash@{0}, without `--theirs`. What did
>> you mean in the previous example, and why was `--theirs` necessary in
>> the call there?
> "--theirs" was necessary since I want the file exactly as it is in the
> stash - any conflicts from applying the file from stash should be
> automatically resolved using the hunk from the stash

But "--theirs" is to take their version unconditionally, isn't it? There is no "if conflicted take theirs", or "take theirs only in conflicted parts, but otherwise take a natural merge result". At least, I do not recall writing the code to behave that way.

So I am not sure if you are getting what you _think_ you are gettin by passing "--theirs".

Devste Devste· Nov 6, 2024, 10:16 UTC · re: Junio C Hamano · lore

Re: 2.43+ git checkout --theirs on stash error - no alternative?

Afaik it means any conflicts should be resolved using --theirs strategy (like in git merge-file --theirs) and if I remember correctly, this is also how it behaved when testing it.

On Mon, 4 Nov 2024 at 11:17, Junio C Hamano <gitster@pobox.com> wrote:
Show 30 quoted lines
>
> Devste Devste <devstemail@gmail.com> writes:
>
> > On Mon, 28 Oct 2024 at 00:38, Taylor Blau <me@ttaylorr.com> wrote:
> >>
> >> On Sun, Oct 27, 2024 at 11:31:05PM +0100, Devste Devste wrote:
> >> > Turns out the previous behavior can be achieved with
> >> > git restore --source='stash@{0}' -- "some-file.txt"
> >>
> >> Hmm. What you wrote above here makes sense, but I agree with the
> >> original change from Junio (CC'd) that using `--theirs` does not make
> >> sense when the source is a tree-ish and not the index directly.
> >>
> >> This is different, though, since here you are just trying to check out
> >> the contents of some-file.txt at stash@{0}, without `--theirs`. What did
> >> you mean in the previous example, and why was `--theirs` necessary in
> >> the call there?
>
> > "--theirs" was necessary since I want the file exactly as it is in the
> > stash - any conflicts from applying the file from stash should be
> > automatically resolved using the hunk from the stash
>
> But "--theirs" is to take their version unconditionally, isn't it?
> There is no "if conflicted take theirs", or "take theirs only in
> conflicted parts, but otherwise take a natural merge result".  At
> least, I do not recall writing the code to behave that way.
>
> So I am not sure if you are getting what you _think_ you are gettin
> by passing "--theirs".
>

← back to recent threads