Search code examples
gitgit-mergegit-merge-conflict

Git merge keep and commit conflicted state


I found some solutions to force an overwrite using ours or theirs strategies, but is there a way to just commit the merge in the conflicted state?

Before you ask why it's not for me, I'm just doing it for someone else.

e.g.

<<<<<<< HEAD
this is some content
=======
this is different content 
>>>>>>> main

Keep this state and commit it. Hopefully should be possible since you can do it manually ? (i.e. git add without fixing it)

Thank you!

Answer is just to write the command as a one liner

git merge main --no-edit || { git add -u . && git commit --no-edit ; }

will merge main into your branch and if it creates a merge conflict, it will just add the files without changing it and commit it with the default merge message


Solution

  • Hopefully should be possible since you can do it manually ? (i.e. git add without fixing it)

    Yup, just git add the conflicted file(s) without fixing, and commit. If you know there's going to be a conflict, just say

    git merge otherbranch; git add .; git commit -m 'shut up and merge'