git-mediate
Tool to help resolving git conflicts
https://github.com/Peaker/git-mediate
| LTS Haskell 24.16: | 1.1.0 |
| Stackage Nightly 2025-10-23: | 1.1.0 |
| Latest on Hackage: | 1.1.0 |
git-mediate-1.1.0@sha256:69b5922b7ff7dcd91f871f77a592a6a51c8fd968b6440b0dc8219b95ed8d3f08,3767Module documentation for 1.1.0
There are no documented modules for this package.
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
Using package managers
- macOS:
brew install git-mediate - Linux (debian):
apt-get install git-mediate
Using haskell-stack
- Install haskell stack
- Run:
stack install git-mediate
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/.
Changes
1.1.0 / 2024.09.20
--split-markersoption to help users split large conflicts to smaller parts--lines-added-aroundoption to auto-resolve conflicts of line added from different sides- Command-line options are are also parsed from the
GIT_MEDIATE_OPTIONSenvironment variables - Can disable auto-resolution with the
--no-trivial,--no-reduce, and--no-line-endingsflags - Improved
--editorsupport for VS Code and Xcode - Fixed handling of filenames containing spaces and special characters
1.0.9 / 2023.07.25
- Do not warn when git is set to use
zdiff3conflict style - Resolve line ending conventions changes (i.e changes from Unix/Windows line endings)
- Preserve file modes when resolving conflicts (i.e executable scripts remain executable)
- Handle changes in
git statusformatting for files in spaces in their names --contextoption for-dmode to control size of context shown around diff- Fixed parsing of conflicts with nested recursive conflicts
--editorgoes to the location of the first conflict in the file
1.0.8.1 / 2020.10.13
- First release on Debian (entered Debian unstable at 2023.07.20)
- Build maintenance (anti-bitrot)
1.0.6 / 2020.01.07
--merge-fileoption to merge specific file, even if file is not marked as conflicted- Reduce add/add conflicts with matching prefix/suffix lines
- Add support for
--untabify
1.0.5 / 2018.07.24
- Windows compatibility fixes
1.0.1 / 2018.07.24
- Conflict headers for
-doption (i.e “### Conflict 3 of 7”) - Improved error message when not running inside a git repository
1.0 / 2016.12.20
- Renamed to
git-mediate - First release on Hackage
- Add
--versionflag
0.3.2.4 / 2016.12.20
- Reduce conflicts when first or last lines match in all parts
0.3.2.1 / 2015.12.25
--diff2option to dump diffs indiff2format- Fix bug in modify/delete conflicts when not running from the repo’s root
0.3.1.2 / 2015.09.20
- Better error reporting for conflict parsing errors
0.3.1.1 / 2015.09.01
- Support modify/delete conflicts
0.3.0.3 / 2015.08.16
-doption also prints the diffs markers- Support add/add conflicts
- Fixed bug with submodule conflicts
0.3.0.1 / 2015.06.06
- Detect git using
diff2conflict style and add-soption to switch todiff3style - Fixed bug with filenames containing spaces
0.2.0.2 / 2015.02.03
- Support for terminals without color
0.2.0.1 / 2015.01.12
- Don’t keep
.bkbackups files for content before resolution
0.2 / 2014.12.18
-doption for displaying the remaining conflicts
0.1.0.1 / 2014.12.10
- Conflict also resolves if both sides match (regardless of base also matching)
Development started / 2014.12.1
- Tool developed started originally as “resolve-trivial-conflicts”