Ever build on a branch which meanwhile was squashed-merged into main
and then you wanted to merge a pull request that was based on that branch? You know, the one that has a commit that conflicts with the squashed commit in main
?
This tool creates a "magic" merge commit that resolves the conflict by connecting the two branches together, allowing you to merge without conflicts.
Execute is with following command:
jbang do@koppor/magic-merge-commit <pr-number>
For this, you need to have jbang installed.
If you don't want to install jbang, place gg.cmd
into the root of your git repository and execute as follows:
- Linux/macOS:
sh ./gg.cmd jbang do@koppor/magic-merge-commit <pr-number>
- Windows:
.\gg.cmd jbang do@koppor/magic-merge-commit <pr-number>
The pull request starts with one commit.
Another improvement is needed. It should be reviewed separate pull request, but needs the first pull reuqest.
Therefore, a new branch is created and a commit is added to it. Finally, a second pull request is created, based on the first one, which is still opened.
The conflicting change in main
.
The second commit in the pull request conflicts with the main
branch, which has its own commit.
The first pull request was added as commit to the main
branch.
There is no git merge commit and there is no git connect with the pull request.
The only indicator is #1
in the commit message.
This tool creates a new commit that has both main
and pr-last-commit
as parents.
This commit "magically" resolves the conflict by wiring the two branches together.
This "magic" merge commit now merges cleanly.
gitk
was used to visualize the commits. Learn more about it at lostechies.- The scenario is available at squash-merge-demo.
- Background is available at a blog post.