Skip to content

Instantly share code, notes, and snippets.

@aeneasr
Last active December 23, 2018 15:29
Show Gist options
  • Save aeneasr/5f09505855adfe846f001b5c7b7705d6 to your computer and use it in GitHub Desktop.
Save aeneasr/5f09505855adfe846f001b5c7b7705d6 to your computer and use it in GitHub Desktop.
Resolving issues with git merge conflicts

Sometimes, maintainers choose to, for example, squash commit PRs into master. When you base off another branch of the PR, this may lead to serious merge conflicts which seem unresolvable (because the commit has been rewritten). In that case, the easiest path forward is to create a patch and apply it to a new branch based off master:

$ git fetch origin # assuming "origin" is the main repo, not your fork
$ git add -A
$ git commit -a -m "unstaged" # make sure everything is committed before you go ahead.
$ git diff origin/master > ~/patch.p # This must be outside of your repo
$ git checkout origin/master -b patch-1
$ git apply ~/patch.p
$ git commit -a -s -m "..."
$ git push HEAD:<fork-remote-id>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment