Assuming that there was a:
PR1based on branchmainPR2based 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 PR1# if branch was deleted - restore it- Create a patch file that captures the changes made in PR2 relative to the state of the PR1, prior to merging it into main branch:
git diff PR1..PR2 --full-index --binary > /tmp/diff.patch - Create a new branch
resolve-conflicts:git switch -c resolve-conflicts - Apply the changes from
PR2to theresolve-conflictsbranch: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 5, which contains the changes from
PR2, into thePR2branch:git merge resolve-conflicts
After completing these steps, the actual main branch should now be mergeable into PR2 without conflicts.