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
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"
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:
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