1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
|
# Introduction
Handling conflicts is difficult!
One useful way to handle them, is to use git's diff3 conflict style:
```shell
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](https://docs.haskellstack.org/en/stable/)
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](https://docs.haskellstack.org/en/stable/))
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/>.
|