Search code examples
gitgit-cherry-pick

How to squash several commits into a single one when merge issues arise


I made changes into various commits in a branch that diverges from upstream. Now I want to squash them all into a single one, based on upstream's current state. But conflicts issues arise, and while it's not a problem to manually fix them, it breaks all the methods I tried to create a proper single commit:

  • patch created with git diff or git format-patch fails to apply
  • git cherry-pick won't let you --continue unless you commit after fixing merge issues. I end up with two commits instead of one.

How to create a proper single commit to send to upstream?


Solution

  • I recommend squashing the commits on your local repository first. That way you get one commit that you can then rebase onto the remote branch.