Neovim integration for git-mediate - a tool that transforms git conflict resolution from a nightmare into a breeze.
The philosophy of git-mediate is simple:
- Identify which of the two changes is simpler
- Apply that simpler change to the other two hunks
- Run git-mediate
- The conflict is resolved!
Instead of mentally merging both sides of a conflict, you pick the simpler side and mirror it. Git-mediate then auto-resolves by detecting when one hunk matches the base.
Say we have this conflict:
<<<<<<< HEAD
function calculate(a, b) {
logger.debug("Calculating sum of", a, "and", b);
return a + b;
||||||| 86dd402
function calculate(a, b) {
return a + b;
=======
function calculate(a, b) {
if (typeof a !== "number" || typeof b !== "number") {
throw new TypeError("Both arguments must be numbers");
}
return a + b
>>>>>>> feature-branch
}The simpler change is the logging addition. Apply it to the base and theirs sections:
<<<<<<< HEAD
function calculate(a, b) {
logger.debug("Calculating sum of", a, "and", b);
return a + b;
||||||| 86dd402
function calculate(a, b) {
logger.debug("Calculating sum of", a, "and", b);
return a + b;
=======
function calculate(a, b) {
logger.debug("Calculating sum of", a, "and", b);
if (typeof a !== "number" || typeof b !== "number") {
throw new TypeError("Both arguments must be numbers");
}
return a + b
>>>>>>> feature-branch
}Now git-mediate detects the top hunk equals the base, so it chooses the other side and runs git add.
<<<<<<< HEAD
function calculate(x, y) {
logger.debug("Calculating sum of", x, "and", y);
if (typeof y !== "number" || typeof x !== "number") {
throw new TypeError("Both arguments must be numbers");
}
return x + y
||||||| 86dd402
function calculate(a, b) {
logger.debug("Calculating sum of", a, "and", b);
if (typeof a !== "number" || typeof b !== "number") {
throw new TypeError("Both arguments must be numbers");
}
return a + b
=======
function calculate(a, b) {
// ... complex logic changes ...
return result
>>>>>>> feature-branch
}One side renames variables, the other adds complex code. Simply rename the variables in the base and theirs sections — git-mediate handles the rest.
This plugin provides:
- Character-level diff highlighting in the buffer itself (similar to Emacs's smerge)
- Quick conflict navigation via quickfix list
- Neovim 0.9+
- git-mediate CLI
- vscode-diff.nvim
-- lazy.nvim
{
"Sharonex/git-mediate.nvim",
dependencies = { "esmuellert/vscode-diff.nvim" },
config = function()
require("git-mediate").setup()
end,
}| Command | Description |
|---|---|
:GitMediate |
Save, run git-mediate, show remaining conflicts in quickfix |
:GitMediateToggle |
Toggle diff view between Ours vs Base / Theirs vs Base |
Default: <leader>g[ runs :GitMediate
In quickfix: <CR> jumps to conflict location.
Conflicts are automatically highlighted with character-level diffs:
- Green: Ours section
- Blue: Base section
- Red: Theirs section
- git-mediate — the conflict resolution engine
- vscode-diff.nvim — character-level diff algorithm
