git/list[1] front-page[2] threads[3] people[4] search[5] about
 

git-rebase produces incorrect output

From
PRPavel Roskin <plroskin@gmail.com>
Date
Nov 29, 2019, 08:21 UTC
Message-ID
<CAN_72e2h2avv-U9BVBYqXVKiC+5kHy-pjejyMSD3X22uRXE39g@mail.gmail.com>
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
Next: Philip Oakley
Message 1 of 6 in “git-rebase produces incorrect output”
  1. Pavel RoskinNov 29, 2019
  2. Philip OakleyNov 29, 2019
  3. Pavel RoskinNov 29, 2019
  4. Elijah NewrenNov 30, 2019
  5. Elijah NewrenNov 30, 2019
  6. Junio C HamanoNov 30, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.