User:Novem Linguae/Essays/Rebasing and merge conflicts

The dreaded merge conflict. Here's how to solve them. Written from a Windows and VS Code perspective.

Rebasing a GitHub pull request edit

Ugh. What a nightmare.

Update with merge commit edit

This is probably the way to go. Force pushing makes it so that I can't check out the PR with VS Code's GitHub extension.

Option 1 edit

  • repo -> ... -> Settings -> General -> tick "Always suggest updating pull request branches"
  • Go back to the PR.
  • At the bottom, next to the button that says "Update branch", click the down arrow
  • Select "Update with merge commit"
  • Click "Update branch"
Obsolete and buggy. Suggest using "update with merge commit", option 1
The following discussion has been closed. Please do not modify it.


Option 2 edit

TODO: There's probably a manual way to do this.

Update with rebase edit

VS Code's GitHub extension does not handle rebasing a GitHub PR at all. Should do "Update with merge commit" above instead.

Option 1 edit

  • repo -> ... -> Settings -> General -> tick "Always suggest updating pull request branches"
  • Go back to the PR.
  • At the bottom, next to the button that says "Update branch", click the down arrow
  • Select "Update with rebase"
  • Click "Update branch"

Option 2 edit

I did a lot of Googling and trying things, none of it worked. Finally, Taavi gave me a workflow to use in the command line that works.

  • cd to repo
  • git checkout master
  • git fetch upstream
  • git rebase upstream/master
  • git checkout vector-2022-bugs - Look at the branch name at the bottom of the PR. Do NOT use the branch name generated by VS Code's PR review plugin, e.g. pr/Gonzom/1915. Do NOT use the repo name by accident, e.g. Gonzom/twinkle-fixes (the branch name is in bold to the left of the repo name). If they used the master branch for their PR, you cannot edit their PR.
  • git rebase master
  • if merge conflict...
    • 2 way editor (don't use VS Code's 3 way editor, it's terrible, disable it by setting git.mergeEditor to false)
      • git status – to see what files have conflicts (highlighted in red)
      • foreach file
        • open those files in editor
        • resolve conflicts manually (search for <<<<)
        • save
        • stage
      • click "continue" in VS Code's git panel, or git rebase --continue
  • if your own patch:
    • git push origin vector-2022-bugs --force
  • if someone else's patch that you opened via the VS Code GitHub PR extension:
    • git push Gonzom pr/Gonzom/1741:theirBranchName --force

Rebasing a Gerrit patch edit

Much easier.

  • Simple rebases can be handled by navigating to the webpage of the patch, then clicking the "Rebase" button in the top right.
  • Merge conflicts can be solved using the procedure at mw:Technical contributor onboarding/Resolve merge conflict. Basically...
    • git rebase master
    • git stage the files when you're done manually resolving the merge conflicts.
    • git status to see if you missed anything
    • git rebase --continue when ready to finalize