MyNixOS website logo
Description

Tool to help resolving git conflicts.

Git conflict resolution has never been easier

When encountering a conflict, you can sometimes imagine: if only I could have applied one of these patches BEFORE the other rather than concurrently, I wouldn't be in this mess!

Well, with git-mediate, you can!

In any conflicted state - git-mediate shows you the 2 diffs involved. By applying these diffs to the base version and the other version, you emulate the situation where the patch had already existed when the other had been applied.

Reapply git-mediate, it will validate that you've indeed applied it correctly, and bam: conflict disappeared!

Git-mediate also lets you handle modify/delete conflicts (there's no sane way in git to show what the modification actually was)

Git-mediate also streamlines jumping to the conflicts with your editor, either with the `-e` option to invoke your editor, or via the standard line number format, which is parsed by all major editors, to allow use of "jump to next error" keys.

Git-mediate especially shines with automatic source transformation tools such as renamers.

In a conflicted state, re-apply a rename that caused the conflict, run git-mediate without opening any files, and the conflicts are gone!

Introduction

Handling conflicts is difficult!

One useful way to handle them, is to use git's diff3 conflict style:

git config --global merge.conflictstyle diff3

And then when you get a conflict, it looks like:

Unconflicted stuff

<<<<<<< HEAD
Version A changes
|||||||
Base version
======= Version B
Version B changes
>>>>>>>

More unconflicted stuff here

Then you are supposed to manually merge the useful changes in the top and bottom parts, relative to the base version.

A useful way to do this is to figure out which of the changes (Version A or Version B) is a simpler change.

Perhaps one of the versions just added a small comment above the code section:

Unconflicted stuff

<<<<<<< HEAD
Added a comment here
BASE
|||||||
BASE
======= Version B
BASE and complex changes here
>>>>>>>

More unconflicted stuff here

One easy thing to do, mechanically, is to apply the simple change to the other 2 versions. Thus, it becomes:

Unconflicted stuff

<<<<<<< HEAD
Added a comment here
BASE
|||||||
Added a comment here
BASE
======= Version B
Added a comment here
BASE and complex changes here
>>>>>>>

More unconflicted stuff here

Now, you can run this little utility: git-mediate, which will see the conflict has become trivial (only one side changed anything) and select that side appropriately.

When all conflicts have been resolved in a file, "git add" will be used on it automatically.

Simpler case

You might just resolve the conflicts manually and remove the merge markers from all of the conflicts.

In such a case, just run git-mediate, and it will "git add" the file for you.

Installation

Recommended: Using haskell-stack

  1. Install haskell stack
  2. Run: stack install git-mediate

Alternative install: from sources

Clone it:

git clone https://github.com/Peaker/git-mediate
cd git-mediate

Option #1: Build & install using stack: stack install (make sure you installed haskell stack)

Option #2: Build & install using cabal: cabal install (make sure ~/.cabal/bin is in your $PATH)

Use

Call the git-mediate from a git repository with conflicts.

Additional features

Open editor

You can use the -e flag to invoke your $EDITOR on every conflicted file that could not be automatically resolved.

Show conflict diffs

Sometimes, the conflict is just a giant block of incomprehensible text next to another giant block of incomprehensible text.

You can use the -d flag to show the conflict in diff-from-base form. Then, you can manually apply the changes you see in both the base and wherever needed, and use git-mediate again to make sure you've updated everything appropriately.

License

Copyright (C) 2014-2023 Eyal Lotem

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License only.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

Metadata

Version

1.0.9

Executables (1)

  • bin/git-mediate

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows