Consider a case where you have multiple features that all depending on each-other going into master at different times. Feature-C depends on Feature-B, and Feature-B depends on Feature-A and so on...
If we squash merge Feature-A into master we first have to resolve our base in Feature-B before it can be merged. Below is an example of resolving it after Feature-A has been merged into master (make sure master is up-to-date).
git fetch --all
git rebase --onto master Feature-A Feature-B
git push -f
To resolve Feature-C we need the old-base(Feature-B) that C is depending on; which is now rewritten since we forced-pushed the changes to origin. But the base exist in the commit logs for Feature-C, and we can create a new base from the commit hash in C's logs where we first started basing of Feature-B.
Again with the new base created we can now do:
git rebase --onto master old-base Feature-C
git push -f
In sitations where there are open PRs and origin/master history has been modifed and forced-pushed.
-
Find the last commit in the old master before the first commit of your branch (copy), e.g.
git rebase --onto origin/main $(git merge-base main branch-your-branch-depend-on) your-branch
-
git checkout master && git pull
-
git checkout your-branch
-
git rebase --onto master last-commit-before-first-pr-commit
(rebase every commit after last-commit and put it onto master). -
Resolve any conflicts.
-
git push -f