Git Mailing List Archive on lore.kernel.org
 help / color / Atom feed
From: Pavel Roskin <plroskin@gmail.com>
To: git@vger.kernel.org
Subject: git-rebase produces incorrect output
Date: Fri, 29 Nov 2019 00:21:40 -0800
Message-ID: <CAN_72e2h2avv-U9BVBYqXVKiC+5kHy-pjejyMSD3X22uRXE39g@mail.gmail.com> (raw)

Hi!

I've discovered an issue with "git rebase" producing a subtly
incorrect file. In fact, that files even compiled but failed in unit
tests! That's so scary that I'm going to stop using "git rebase" for
now. Fortunately, "git rebase --merge" is working correctly, so I'll
use it. Too bad there is no option to use "--merge" by default.

The issue was observed in git 2.23 and reproduced in today's next
branch (2.24.0.449.g4c06f74957) on up-to-date Fedora 31 x86_64.

I've created a repository that demonstrates the issue:
https://github.com/proski/git-rebase-demo

The branch names should be self-explanatory. "master" is the base,
"branch1" and "branch2" contain one change each. If "branch1" is
rebased on top of "branch2", the result is incorrect, saved in the
"rebase-bad" branch. If "git rebase -m" is used, the result is
correct, saved in the "merge-good" branch.

The files in "rebase-bad" and "merge-good" have exactly the same lines
but in a different order. Yet the changes on branch1 and branch2
affect non-overlapping parts of the file. There should be no doubt how
the merged code should look like.

I believe the change on branch2 shifts the lines, so that the first
change from branch1 is applies to a place below the intended location,
and then git goes back to an earlier line to apply the next hunk. I
can imagine that it would do the right thing in case of swapped blocks
of code. Yet I have a real life example where it does a very wrong
thing.

Indeed, "git diff origin/branch2 origin/rebase-bad" and "git diff
origin/branch2 origin/merge-good" both produce diffs of 9957 bytes
long, different only in the order of the hunks.

Another interesting data point - "git rebase --interactive" is working
correctly.

-- 
Regards,
Pavel Roskin

             reply index

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-29  8:21 Pavel Roskin [this message]
2019-11-29 13:31 ` Philip Oakley
2019-11-29 21:28   ` Pavel Roskin
2019-11-30  4:22 ` Elijah Newren
2019-11-30 16:37   ` Elijah Newren
2019-11-30 17:58   ` Junio C Hamano

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

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

  git send-email \
    --in-reply-to=CAN_72e2h2avv-U9BVBYqXVKiC+5kHy-pjejyMSD3X22uRXE39g@mail.gmail.com \
    --to=plroskin@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

Git Mailing List Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/git/0 git/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 git git/ https://lore.kernel.org/git \
		git@vger.kernel.org
	public-inbox-index git

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.git


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git