Search code examples
gitrebase

Merge conflicts during reword (git rebase -i)


It seems, I am lacking some understanding of git.

I am currently in the process of an extensive

git rebase -i --root

on origin/main(master), which is not a fork.

  • Commits are not reordered
  • There are several merge commits into main

My todo file contains only

  • pick and
  • reword,

as many commit messages must be changed to pass commit linting.

Why do I have to manually resolve such merge conflicts?

CONFLICT (content): Merge conflict in file1
CONFLICT (content): Merge conflict in file2

I would expect that changing commit messages should be possible independently of the changes in the code base.

Could one reason be past forced updates?


Solution

  • Because you did not use --rebase-merges, you are missing merges with changes (like conflict resolution)... and that is causing the current conflicts in the rebase. If you will only do a reword of a commit (and you won't change any files), you should try:

    git rebase --rebase-merges -i --root
    

    Then, everytime you hit a conflict (like in some merge commits where you faced them originally), you can do this to reuse the original conflict resolution without having to do any additional work:

    git restore --staged --worktree --source=REBASE_HEAD -- .
    git rebase --continue
    

    Until the rebase is finished. And, in case it is not obvious, you must not introduce any new changes in the files while you are doing the rebase because using this would remove those changes on later commits where there are conflicts.