0

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

mclslee
  • 458
  • 1
  • 5
  • 15

1 Answers1

1

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'
matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Right, but I meant as part of the `git merge` command; trying to avoid the manual step. – mclslee Mar 04 '22 at 17:25
  • 1
    You'd have to write your own custom merge strategy for that. But I don't see what the issue is. If you know there's going to be a conflict, the merge and add all and commit can be a single command. – matt Mar 04 '22 at 17:26
  • Haha touche.. I didn't even think about using operators to continue and add it / commit it with --no-edit as separate command. Will mark you as answer, thank you! – mclslee Mar 04 '22 at 18:29