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"
1 Like

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