Zum Hauptinhalt springen

Manually merging git commits

Today I learned how to manually merge a git branch, when you want to be sure to compare each difference after a merge.

  1. Don’t fast-forward and commit when merging:

    git merge --no-ff --no-commit feature-branch
    
  2. Now changes are applied and staged. Because we want to inspect each difference, we remove all changes from the staging area:

    git restore --staged .
    
  3. Changes are now only applied, but not staged. So we can now easily inspect each change (via cli or IDE) and remove all changes we don’t want to keep.

    git add --patch -- . # to add changes to the staging area
    git checkout --patch -- . # to fully remove applied changes
    

Open Questions:

  • I don’t know how to start the merge-tool of my choice, so I could use e.g. my IDE to merge more complicated patches.