TL;DR: this is actually pretty normal for your case
Because rebase consists of copying commits, and you're copying commits into a new and slightly different source base, these kinds of conflicts, and having to re-resolve them, is pretty normal.
You can look into using Git's rerere.enabled
feature (see Are there any downsides to enabling git rerere?) to automate some of this. I have not tried that.
Long
Using your link—https://github.com/mesonbuild/meson/pull/3277—I was able to clone the repository and find the patch:
$ git clone https://github.com/mesonbuild/meson
Cloning into 'meson'...
remote: Counting objects: 33400, done.
[snip]
$ cd meson/
$ git fetch origin refs/pull/3277/head:refs/heads/feature
remote: Counting objects: 31, done.
remote: Total 31 (delta 20), reused 20 (delta 20), pack-reused 11
[snip]
(this created for me a local branch named feature
which I then checked out). Let's take a look now at the commit graph. This is quite long so I am going to snip some—but not all—irrelevant parts, replacing them with a series of dots:
$ git log --decorate --oneline --graph master feature
* 9b2e533d (origin/master, origin/HEAD, master) Always build parser objects anew to avoid leaking old data.
* 977acc94 Do not leave open file handlers, use context manager to clean them up
* 8efd9400 pkgconfig generator: Add required version
* f6f07840 Merge pull request #2976 from dzabraev/fix-reversed-order
|\
| * ea6e9298 keep include paths order
............
* | c4192a04 Support data types larger than 128 bytes
| | * 6a3db989 (HEAD -> feature) Fixing typo closes #2865
| | * 8fe1adcb Fixing typo closes #2865
| | * d3554ceb Fixing PR changes closes #2865
| | |\
| |_|/
|/| |
* | | 3e48d476 Squash target_type warning for jar targets
................
* | | 12bac512 Fix b_ndebug=if-release silently not working
|\ \ \
| * | | 6910f604 Disable b_ndebug tests on MSVC
................
| * | | 39a3bdb4 Add tests for b_ndebug=if-release and buildtype default options
* | | | 30827b56 Do not install configure_file output if install_dir is empty. Closes #3270.
|/ / /
| | * 21e7e1fe PR review changes closes #2865
| | * 531120e8 fix2865
| |/
|/|
* | dd614015 Open mesontest logfiles in utf-8 mode
............
Now, the five "most interesting" commits here are the ones that are reachable from feature
—from your pull request—but not from master
:
$ git log --no-decorate --oneline master..feature
6a3db989 Fixing typo closes #2865
8fe1adcb Fixing typo closes #2865
d3554ceb Fixing PR changes closes #2865
21e7e1fe PR review changes closes #2865
531120e8 fix2865
This identifies the commits by their hash IDs. Looking at the graph output above, we can see that 531120e8
and 21e7e1fe
are ordinary commits, but d3554ceb
is a merge commit with two parents: the first one is 21e7e1fe
(your own work), and the second is 3e48d476 Squash target_type warning for jar targets
.
One issue with any git rebase
is that it works by copying commits.1 It is, in any useful sense, impossible to properly copy a merge commit, and rebase doesn't even try. Instead, it just throws out the merge entirely.
Hence, if we now run git rebase -i master
2 while on branch feature
, we'll get a set of four, not five, pick
commands, in our editor session:
$ git rebase -i master
pick 531120e8 fix2865
pick 21e7e1fe PR review changes closes #2865
pick 8fe1adcb Fixing typo closes #2865
pick 6a3db989 Fixing typo closes #2865
# Rebase 9b2e533d..6a3db989 onto 9b2e533d (4 commands)
[snip rest of instructions]
Note that d3554ceb
is not listed here. Git is not going to attempt to copy the merge commit.
When you did the merge, you solved a merge conflict that happened "after" your old commits. Since the rebase isn't keeping the merge, and moreover, your new copies are going to come "after" the point where the conflict occurs, you will have to solve the same conflict again, probably more than once.
1Rebase copies commits using either git cherry-pick
, without any -m
argument, or git apply -3
of a formatted patch.
2What we want here is to rebase on commit 9b2e533d
. In my clone, the names master
and origin/master
both point to this commit hash. I could also run git rebase -i 9b2e533d
.
Solving the conflicts manually
If you just let this rebase run, it immediately hits a merge conflict:
Auto-merging run_unittests.py
CONFLICT (content): Merge conflict in run_unittests.py
Auto-merging mesonbuild/build.py
error: could not apply 531120e8... fix2865
When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
Could not apply 531120e8... fix2865
$ git status
[snip]
both modified: run_unittests.py
I resolved it manually myself using the same method you did in your merge, and ran git rebase --continue
, which promptly hit the problem again:
$ git add run_unittests.py
$ git rebase --continue
[snip editor session]
[detached HEAD bbd74944] fix2865
Author: chitranjali <chitranjali189@gmail.com>
6 files changed, 51 insertions(+)
create mode 100644 test cases/unit/25 shared_mod linking/installed_files.txt
create mode 100644 test cases/unit/25 shared_mod linking/libfile.c
create mode 100644 test cases/unit/25 shared_mod linking/main.c
create mode 100644 test cases/unit/25 shared_mod linking/meson.build
Removing test cases/unit/25 shared_mod linking/installed_files.txt
Auto-merging run_unittests.py
CONFLICT (content): Merge conflict in run_unittests.py
Auto-merging mesonbuild/build.py
error: could not apply 21e7e1fe... PR review changes closes #2865
When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
Could not apply 21e7e1fe... PR review changes closes #2865
This merge conflict is a bit different, but related, and is again in run_unittests.py
—basically, Git is unable to cherry-pick the original commit because its surrounding context is too different. (It might or might not have helped to have resolved the previous conflict by adding the new test after the final two unit tests in this class, rather than before them.)
Fixing that again:
$ git add run_unittests.py
$ git rebase --continue
[snip editor session]
we get yet another merge conflict:
[detached HEAD 08b4eefc] PR review changes closes #2865
Author: chitranjali <chitranjali189@gmail.com>
4 files changed, 10 insertions(+), 11 deletions(-)
delete mode 100644 test cases/unit/25 shared_mod linking/installed_files.txt
Auto-merging run_unittests.py
CONFLICT (content): Merge conflict in run_unittests.py
error: could not apply 8fe1adcb... Fixing typo closes #2865
When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
Could not apply 8fe1adcb... Fixing typo closes #2865
This one occurs because the parent of commit 8fe1adcb
is your own merge commit d3554ceb
, which Git has skipped, so it's comparing d3554ceb
to 8fe1adcb
to see what to copy while comparing d3554ceb
to HEAD
(a commit just built by the previous cherry-pick) to see what it should leave alone. There is one minor white space difference that messes with automatic resolution here.
Fixing that manually in favor of the one with correct white space and continuing, I get:
$ git add run_unittests.py
$ git rebase --continue
The previous cherry-pick is now empty, possibly due to conflict resolution.
If you wish to commit it anyway, use:
git commit --allow-empty
Otherwise, please use 'git reset'
interactive rebase in progress; onto 9b2e533d
Last commands done (4 commands done):
pick 8fe1adcb Fixing typo closes #2865
pick 6a3db989 Fixing typo closes #2865
No commands remaining.
You are currently rebasing branch 'feature' on '9b2e533d'.
nothing to commit, working tree clean
Could not apply 6a3db989... Fixing typo closes #2865
Ignoring the rather odd (though technically OK) directions, I ran:
$ git rebase --continue
Successfully rebased and updated refs/heads/feature.
which might be correct (I know nothing of this software and have not tested any of these versions).
Rebasing without --interactive
This is really quite similar, you just get a lot less interaction. Git uses git format-patch
to turn each of the four (not five) commits into patches and then applies each one with git am --3way
. The first one runs into a merge conflict, which I resolved manually keeping the newly added test function at the end this time:
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: fix2865
Using index info to reconstruct a base tree...
M mesonbuild/build.py
M run_unittests.py
Falling back to patching base and 3-way merge...
Auto-merging run_unittests.py
CONFLICT (content): Merge conflict in run_unittests.py
Auto-merging mesonbuild/build.py
error: Failed to merge in the changes.
Patch failed at 0001 fix2865
The copy of the patch that failed is found in: .git/rebase-apply/patch
When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
[snip editor session on run_unittests.py]
$ git add run_unittests.py
$ git rebase --continue
Applying: fix2865
Applying: PR review changes closes #2865
Using index info to reconstruct a base tree...
M mesonbuild/build.py
M run_unittests.py
.git/rebase-apply/patch:10: trailing whitespace.
mlog.warning('''target links against shared modules. This is not
.git/rebase-apply/patch:36: trailing whitespace.
msg = ('''WARNING: target links against shared modules. This is not
warning: 2 lines add whitespace errors.
Falling back to patching base and 3-way merge...
Removing test cases/unit/25 shared_mod linking/installed_files.txt
Auto-merging run_unittests.py
Auto-merging mesonbuild/build.py
Applying: Fixing typo closes #2865
Using index info to reconstruct a base tree...
M run_unittests.py
Falling back to patching base and 3-way merge...
Auto-merging run_unittests.py
CONFLICT (content): Merge conflict in run_unittests.py
error: Failed to merge in the changes.
Patch failed at 0003 Fixing typo closes #2865
The copy of the patch that failed is found in: .git/rebase-apply/patch
When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
[snip editor session again]
$ git add run_unittests.py
$ git rebase --continue
Applying: Fixing typo closes #2865
No changes - did you forget to use 'git add'?
If there is nothing left to stage, chances are that something else
already introduced the same changes; you might want to skip this patch.
When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
It turns out that this particular fix is no longer required, so it's correct to skip it:
$ git rebase --skip
Applying: Fixing typo closes #2865
Using index info to reconstruct a base tree...
M run_unittests.py
Falling back to patching base and 3-way merge...
No changes -- Patch already applied.
and now the rebase is finished.