git-mediate
Tool to help resolving git conflicts
https://github.com/Peaker/git-mediate
LTS Haskell 22.33: | 1.0.9 |
Stackage Nightly 2024-09-07: | 1.0.9 |
Latest on Hackage: | 1.0.9 |
git-mediate-1.0.9@sha256:960a829f5c62b0d31962ed0bb92045e5320411f3a56bd9dc242679795745417a,3606
Module documentation for 1.0.9
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
Recommended: Using haskell-stack
- Install haskell stack
- 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/.
Changes
1.0.9 / To be released
- Do not warn when git is set to use
zdiff3
conflict 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 status
formatting for files in spaces in their names --context
option for-d
mode to control size of context shown around diff- Fixed parsing of conflicts with nested recursive conflicts
--editor
goes 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-file
option 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
-d
option (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
--version
flag
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
--diff2
option to dump diffs indiff2
format- 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
-d
option also prints the diffs markers- Support add/add conflicts
- Fixed bug with submodule conflicts
0.3.0.1 / 2015.06.06
- Detect git using
diff2
conflict style and add-s
option to switch todiff3
style - 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
.bk
backups files for content before resolution
0.2 / 2014.12.18
-d
option 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”