Quick way resolve git conflict when merging?

Hi !
Anyone has a good hack to quickly resolve conflict when merging git branches ?

There is no simple way. By definition, the computer canā€™t make a good decision on merge conflicts so a human needs to.

It is possible to choose one side of a conflict with
git checkout --ours -- . (or --theirs).
That alone is rarely enough, but it can be useful if one of the conflicting changes is a ā€œsimpleā€ change. Use --ours or --theirs to checkout the version with ā€œharderā€ change, and then redo the ā€œsimpleā€ one on top of that.

If you find yourself repeatedly resolving the same merge conflicts, I recommend turning on git-rerere so Git remembers your conflict resolutions.

There are different merge tools that make it easy to go through each conflict and resolve it, for example GitHub - lenormf/kakmerge: A Kakoune-based mergetool for Git

2 Likes

That is what I was looking for !

Havenā€™t tried kakmerge yet, but I sometimes use these mappings to quickly resolve to one side of a conflict:

map global object m %{c^[<lt>=]{4\,}[^\n]*\n,^[<gt>=]{4\,}[^\n]*\n<ret>} -docstring 'conflict markers'
define-command conflict-use-1 %{
	evaluate-commands -draft %{
		execute-keys <a-h>h/^<lt>{4}<ret><a-x>d
		execute-keys h/^={4}<ret>j
		execute-keys -with-maps <a-a>m
		execute-keys d
	}
} -docstring "resolve a conflict by using the first version"
define-command conflict-use-2 %{
	evaluate-commands -draft %{
		execute-keys j
		execute-keys -with-maps <a-a>m
		execute-keys dh/^>{4}<ret><a-x>d
	}
} -docstring "resolve a conflict by using the second version"
3 Likes

Thanks thatā€™s super valuable,

I tried to implement something similar but didnā€™t thought about creating a new ā€˜objectā€™, itā€™s definitely the way to go !

Reading following blog post was helpful for me to better understand ā€œmerge conflictā€ mechanics:

1 Like

I just packed @krobelus solution and added some other useful commands in a plugin.

This is somewhat unrelated to kakoune, but I find itā€™s also helpful to set merge.conflictstyle=zdiff3 in your git configuration. It gives some extra info in trying to resolve conflicts that might be enough for you to replace a 3-way merge tool. It probably wonā€™t play well with the above objects however

2 Likes