git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: Dave Kaminski <davekaminski@gmail.com>, git@vger.kernel.org
Subject: Re: Incorrect behavior from git checkout --patch
Date: Sun, 11 Aug 2019 10:54:31 +0100	[thread overview]
Message-ID: <a243aa2f-b237-db8e-0cac-cb3f776fdbd2@gmail.com> (raw)
In-Reply-To: <CA+zjYZsojm0QgHBC3GFb2NeZR1aK3Uh7vO4ojBzsMKVvP6X+Tg@mail.gmail.com>

Hi Dave

Thanks for the bug report. I've tried to reproduce it on the latest 
master, version 2.22.0 and 2.20.1 and am unable to do so. I thought it 
might be related to a bug I recently fixed[1] but it does not appear to 
be. I've appended the files I used below just in case I made a mistake 
translating your patches to files that can be used with git checkout.

Best Wishes

Phillip

[1] 
https://github.com/git/git/commit/1b074e15d0f976be2bc14f9528874a841c055213#diff-588be9a03d1f7e33db12f186aad5fde9

pre-image

block_one {
line 1
line 2
line 3
2 4 6 8
line 4
line 5
line 6
2 4 6 8
line 7
line 8
line 9
2 4 6 8
line 10
line 11
line 12
}

block_two {
line 1
line 2
line 3
2 5 6 9
line 4
line 5
line 6
2 5 6 9
line 7
line 8
line 9
2 5 6 9
line 10
line 11
line 12
}

post-image

block_one {
line 1
line 1.5
line 2
line 2.5
line 3
2 4 6 8
line 4
line 4.5
line 5
line 5.5
line 6
2 4 6 8
line 7
line 7.5
line 8
line 8.5
line 9
2 4 6 8
line 10
line 10.5
line 11
line 11.5
line 12
}

block_two {
line 1
line 1.5
line 2
line 2.5
line 3
2 5 6 9
line 4
line 4.5
line 5
line 5.5
line 6
2 5 6 9
line 7
line 7.5
line 8
line 8.5
line 9
2 5 6 9
line 10
line 10.5
line 11
line 11.5
line 12
}



On 10/08/2019 21:12, Dave Kaminski wrote:
> I am observing git checkout --patch making changes to the wrong lines of a file.
> 
> This is with a clean install of git version 2.20.1 on a debian docker
> container (image tag 10.0 which is also "latest" as of this writing).
> 
> With a diff that looks like the following:
> 
> diff --git a/file.txt b/file.txt
> index 868aa22..ea4d786 100644
> --- a/file.txt
> +++ b/file.txt
> @@ -1,35 +1,51 @@
>   block_one {
>   line 1
> +line 1.5
>   line 2
> +line 2.5
>   line 3
>   2 4 6 8
>   line 4
> +line 4.5
>   line 5
> +line 5.5
>   line 6
>   2 4 6 8
>   line 7
> +line 7.5
>   line 8
> +line 8.5
>   line 9
>   2 4 6 8
>   line 10
> +line 10.5
>   line 11
> +line 11.5
>   line 12
>   }
> 
>   block_two {
>   line 1
> +line 1.5
>   line 2
> +line 2.5
>   line 3
> -2 5 6 9
> +2 4 6 8
>   line 4
> +line 4.5
>   line 5
> +line 5.5
>   line 6
> -2 5 6 9
> +2 4 6 8
>   line 7
> +line 7.5
>   line 8
> +line 8.5
>   line 9
> -2 5 6 9
> +2 4 6 8
>   line 10
> +line 10.5
>   line 11
> +line 11.5
>   line 12
>   }
> 
> doing a `git checkout --patch -- ./file.txt`, splitting the diff into
> hunks, and discarding all of the hunks that begin with numbers, e.g.
> 
> @@ -22,3 +32,3 @@
>   line 3
> -2 5 6 9
> +2 4 6 8
>   line 4
> 
> the expected state of the file in the working directory is this:
> 
> diff --git a/file.txt b/file.txt
> index 868aa22..9ab67a1 100644
> --- a/file.txt
> +++ b/file.txt
> @@ -1,35 +1,51 @@
>   block_one {
>   line 1
> +line 1.5
>   line 2
> +line 2.5
>   line 3
>   2 4 6 8
>   line 4
> +line 4.5
>   line 5
> +line 5.5
>   line 6
>   2 4 6 8
>   line 7
> +line 7.5
>   line 8
> +line 8.5
>   line 9
>   2 4 6 8
>   line 10
> +line 10.5
>   line 11
> +line 11.5
>   line 12
>   }
> 
>   block_two {
>   line 1
> +line 1.5
>   line 2
> +line 2.5
>   line 3
>   2 5 6 9
>   line 4
> +line 4.5
>   line 5
> +line 5.5
>   line 6
>   2 5 6 9
>   line 7
> +line 7.5
>   line 8
> +line 8.5
>   line 9
>   2 5 6 9
>   line 10
> +line 10.5
>   line 11
> +line 11.5
>   line 12
>   }
> 
> but instead the actual state of the file is this:
> 
> diff --git a/file.txt b/file.txt
> index 868aa22..76fe65d 100644
> --- a/file.txt
> +++ b/file.txt
> @@ -1,35 +1,51 @@
>   block_one {
>   line 1
> +line 1.5
>   line 2
> +line 2.5
>   line 3
>   2 4 6 8
>   line 4
> +line 4.5
>   line 5
> +line 5.5
>   line 6
>   2 4 6 8
>   line 7
> +line 7.5
>   line 8
> +line 8.5
>   line 9
> -2 4 6 8
> +2 5 6 9
>   line 10
> +line 10.5
>   line 11
> +line 11.5
>   line 12
>   }
> 
>   block_two {
>   line 1
> +line 1.5
>   line 2
> +line 2.5
>   line 3
>   2 5 6 9
>   line 4
> +line 4.5
>   line 5
> +line 5.5
>   line 6
>   2 5 6 9
>   line 7
> +line 7.5
>   line 8
> +line 8.5
>   line 9
> -2 5 6 9
> +2 4 6 8
>   line 10
> +line 10.5
>   line 11
> +line 11.5
>   line 12
>   }
> 
> See the changes between "line 9" and "line 10" in both blocks that are
> not correct.
> 

  reply	other threads:[~2019-08-11  9:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-10 20:12 Incorrect behavior from git checkout --patch Dave Kaminski
2019-08-11  9:54 ` Phillip Wood [this message]
2019-08-11 13:47   ` Phillip Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a243aa2f-b237-db8e-0cac-cb3f776fdbd2@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=davekaminski@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).