All of lore.kernel.org
 help / color / mirror / Atom feed
* git apply -3 doesn't work
@ 2020-05-08 10:35 Konstantin Kharlamov
  2020-05-08 13:47 ` Phillip Wood
  0 siblings, 1 reply; 3+ messages in thread
From: Konstantin Kharlamov @ 2020-05-08 10:35 UTC (permalink / raw)
  To: git

As description says. To check that the 3-way merge should actually work subsitute `git apply -3` with `git am -3` in the following steps. This way it works.

# Steps to reproduce

     $ git init
     Initialized empty Git repository in /tmp/foo/.git/
     $ echo hello > file1 && git add file1 && git commit -m "initial commit"
     [master (root-commit) 8334093] initial commit
      1 file changed, 1 insertion(+)
      create mode 100644 file1
     $ git checkout -b mybranch
     Switched to a new branch 'mybranch'
     $ echo bye > file1 && git add file1 && git commit -m "change file1 text"
     [mybranch 1807900] change file1 text
      1 file changed, 1 insertion(+), 1 deletion(-)
     $ git format-patch -1 --stdout > 1.patch
     $ git checkout master
     Switched to branch 'master'
     $ mv file1 file2
     $ git add -u && git add file2 && git commit -m "renamed file1 to file2"
     $ git apply -3 1.patch
     error: file1: does not exist in index

## Expected

Git apply successfully returns

## Actual

It prints

	error: file1: does not exist in index

# Versions

git 2.26.2

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: git apply -3 doesn't work
  2020-05-08 10:35 git apply -3 doesn't work Konstantin Kharlamov
@ 2020-05-08 13:47 ` Phillip Wood
  2020-05-08 13:52   ` Konstantin Kharlamov
  0 siblings, 1 reply; 3+ messages in thread
From: Phillip Wood @ 2020-05-08 13:47 UTC (permalink / raw)
  To: Konstantin Kharlamov, git

Hi Konstantin

On 08/05/2020 11:35, Konstantin Kharlamov wrote:
> As description says. To check that the 3-way merge should actually work 
> subsitute `git apply -3` with `git am -3` in the following steps. This 
> way it works.
> 
> # Steps to reproduce
> 
>      $ git init
>      Initialized empty Git repository in /tmp/foo/.git/
>      $ echo hello > file1 && git add file1 && git commit -m "initial 
> commit"
>      [master (root-commit) 8334093] initial commit
>       1 file changed, 1 insertion(+)
>       create mode 100644 file1
>      $ git checkout -b mybranch
>      Switched to a new branch 'mybranch'
>      $ echo bye > file1 && git add file1 && git commit -m "change file1 
> text"
>      [mybranch 1807900] change file1 text
>       1 file changed, 1 insertion(+), 1 deletion(-)
>      $ git format-patch -1 --stdout > 1.patch
>      $ git checkout master
>      Switched to branch 'master'
>      $ mv file1 file2
>      $ git add -u && git add file2 && git commit -m "renamed file1 to 
> file2"
>      $ git apply -3 1.patch
>      error: file1: does not exist in index

Judging from the error message it never gets as far as trying the 3 way 
merge because it first tries to apply the patch which modifies file1 but 
file1 does not exist in the index. If it were to try a 3 way merge in 
this case then on one side of the merge you've modified file1 and on the 
other side it has been deleted so there would be a merge conflict. The 
reason 'git am' succeeds is that the rename detection kicks in and so it 
applies the patch to file2 rather than file1

Best Wishes

Phillip

> 
> ## Expected
> 
> Git apply successfully returns
> 
> ## Actual
> 
> It prints
> 
>      error: file1: does not exist in index
> 
> # Versions
> 
> git 2.26.2

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: git apply -3 doesn't work
  2020-05-08 13:47 ` Phillip Wood
@ 2020-05-08 13:52   ` Konstantin Kharlamov
  0 siblings, 0 replies; 3+ messages in thread
From: Konstantin Kharlamov @ 2020-05-08 13:52 UTC (permalink / raw)
  To: phillip.wood, git

On 5/8/20 4:47 PM, Phillip Wood wrote:
> Hi Konstantin
> 
> On 08/05/2020 11:35, Konstantin Kharlamov wrote:
>> As description says. To check that the 3-way merge should actually work subsitute `git apply -3` with `git am -3` in the following steps. This way it works.
>>
>> # Steps to reproduce
>>
>>      $ git init
>>      Initialized empty Git repository in /tmp/foo/.git/
>>      $ echo hello > file1 && git add file1 && git commit -m "initial commit"
>>      [master (root-commit) 8334093] initial commit
>>       1 file changed, 1 insertion(+)
>>       create mode 100644 file1
>>      $ git checkout -b mybranch
>>      Switched to a new branch 'mybranch'
>>      $ echo bye > file1 && git add file1 && git commit -m "change file1 text"
>>      [mybranch 1807900] change file1 text
>>       1 file changed, 1 insertion(+), 1 deletion(-)
>>      $ git format-patch -1 --stdout > 1.patch
>>      $ git checkout master
>>      Switched to branch 'master'
>>      $ mv file1 file2
>>      $ git add -u && git add file2 && git commit -m "renamed file1 to file2"
>>      $ git apply -3 1.patch
>>      error: file1: does not exist in index
> 
> Judging from the error message it never gets as far as trying the 3 way merge because it first tries to apply the patch which modifies file1 but file1 does not exist in the index. If it were to try a 3 way merge in this case then on one side of the merge you've modified file1 and on the other side it has been deleted so there would be a merge conflict. The reason 'git am' succeeds is that the rename detection kicks in and so it applies the patch to file2 rather than file1
> 
> Best Wishes
> 
> Phillip
> 

Thank you. I wonder if it would make sense to `git aplly -3 1.patch` to behave similarly to `git am -3 1.patch && git reset HEAD^` (except without modifying reflog). I.e. so all heuristics `git am` makes use of would also apply to `git apply`

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-05-08 13:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-08 10:35 git apply -3 doesn't work Konstantin Kharlamov
2020-05-08 13:47 ` Phillip Wood
2020-05-08 13:52   ` Konstantin Kharlamov

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.