Skip to content

koppor/magic-merge-commit

Repository files navigation

Create Magic Merge Commit

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>

Visualization of the process

1. First pull request is created

The pull request starts with one commit.

First PR

2. Second pull request is created

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.

Second Commit

3. First pull request is merged in to main

First PR Merged

4. main branch has its own commit

The conflicting change in main.

Main has first commit

5. Conflict Arises with the main branch

The second commit in the pull request conflicts with the main branch, which has its own commit.

Conapsflict with main

6. Conflicting state visualized with gitk

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.

Conflicting state

7. The magic commit is created

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.

Magic Commit

8. Merge without conflicts

This "magic" merge commit now merges cleanly.

No Conflicts

More information

About

Creates a magic merge commit to solve GitHub squash-merge issues

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages