Assuming that there was a:
PR1
based on branchmain
PR2
based on PR1
And after squash-merging PR1
into the main
branch,
sometimes we can't just merge PR2
due to a conflicts arising from the commits in PR1
being squashed.
Here's the step-by-step explanation of the Git workflow to resolve this issue:
git switch main
- Reset the
main
branch to the state it was in right afterPR1
was merged:git reset --hard [PR1-SHA-COMMIT]
- Create a patch file that captures the changes made in PR2 relative to the state of the main branch:
git diff main..PR2 > /tmp/diff.patch
- Create a new branch
resolve-merge-issues
:git switch -c resolve-merge-issues
- Apply the changes from
PR2
to theresolve-merge-issues
branch:git apply /tmp/diff.patch
- Create a single commit that combines all the changes from
PR2
:
git commit -a -m "Merge commit"
git switch PR2
- Merge the single commit created in step 6, which contains the changes from
PR2
, into thePR2
branch:git merge resolve-merge-issues
After completing these steps, the actual main branch should now be mergeable into PR2
without conflicts.