All Projects β†’ jakub-g β†’ git-resolve-conflict

jakub-g / git-resolve-conflict

Licence: MIT license
πŸ’² βž• βž– βœ… Resolve merge conflict from command line, in one file, using given strategy (--ours, --theirs, --union)

Programming Languages

shell
77523 projects

Projects that are alternatives of or similar to git-resolve-conflict

ConflictResolver
An Xcode Source Editor Extension that helps resolving merge conflicts. There are three options, namely 'Accept theirs', 'Accept Yours', and 'Keep Both'. Only one click and it will make the change for you automatically.
Stars: ✭ 24 (-45.45%)
Mutual labels:  merge-conflicts, conflict-resolution
revctrl.org
An extract, as complete as I can make it, of content from the revctrl.org wiki
Stars: ✭ 13 (-70.45%)
Mutual labels:  merge-conflicts
magit-imerge
Magit extension for git-imerge
Stars: ✭ 26 (-40.91%)
Mutual labels:  merge-conflicts
SyncedStore
SyncedStore CRDT is an easy-to-use library for building live, collaborative applications that sync automatically.
Stars: ✭ 1,053 (+2293.18%)
Mutual labels:  conflict-resolution
syncthing-resolve-conflicts
A small bash script that handles synchronization conflicts with Syncthing. Inspired by 'pacdiff' from Arch Linux.
Stars: ✭ 61 (+38.64%)
Mutual labels:  conflict-resolution
ConflictJS
Finding and Understanding Conflicts Between JavaScript Libraries
Stars: ✭ 39 (-11.36%)
Mutual labels:  conflict-resolution
Git Imerge
Incremental merge for git
Stars: ✭ 2,322 (+5177.27%)
Mutual labels:  merge-conflicts
Xunique
merge Xcode project file is so easy
Stars: ✭ 1,450 (+3195.45%)
Mutual labels:  merge-conflicts
Fac
Easy-to-use CUI for fixing git conflicts
Stars: ✭ 1,738 (+3850%)
Mutual labels:  conflict-resolution
jdime
syntactic merge tool for java
Stars: ✭ 14 (-68.18%)
Mutual labels:  conflict-resolution

git-resolve-conflict <strategy> <filename>

Resolve merge conflict in just one file, using given strategy (--ours, --theirs, --union)

git resolve-conflict --ours package.json
git resolve-conflict --theirs package.json
git resolve-conflict --union package.json

git resolve-ours package.json
git resolve-theirs package.json
git resolve-union package.json

Why would you need it

To be able to resolve certain well-defined types of merge conflicts, without opening mergetool.

This is particularly useful in automated merge scripts (for example, Jenkins jobs), or if you have large number of well-defined merges to resolve.

Things to be aware of

Note though, this is just a dumb text-based merge resolution script; if you're unlucky, the merged file might be syntactically incorrect.

For example: when using --ours strategy on package.json where both sides added an entry at the end of dependencies or scripts array, the result will be two blocks added without trailing comma between them (hence invalid JSON).

Installation

  • copy /lib/git-resolve-conflict.sh to your .bashrc (this adds just git resolve-conflict)
  • or npm install -g git-resolve-conflict (this also adds 3 other helpers)

Get it on npm

npm installation is the recommended way, so that you can easily get updates in the future.

FAQ

  • Q: Why no updates in 3 years?

  • A: Because it worksβ„’. It's feature-complete.

  • Q: Does it work on Windows?

  • A: Yep, but it'a shell script, so you need a unix-y shell. I'm using it with git bash and it works well.

  • Q: Why you distribute through npm?

  • A: Just to make it easier to install if you happen to have node. The script itself is shell.

TL;DR

It's just a tiny wrapper around git-merge-file to simplify the API. See ./lib/git-resolve-conflict.sh. (I used temp files instead of process substitution to make it msys/mingw-friendly).

It's better than git merge -Xours because that would resolve conflicts for all files. Here we can resolve conflict for just one file.

It's better than git checkout --ours package.json because that would lose changes from theirs even if they are not conflicted. Here we can resolve conflict using a three-way merge and keep the non-conflicted changes from both sides.

See also http://stackoverflow.com/q/39126509/245966

Description

Say you have multiple git branches and you want to merge between them, and always resolve conflicts in a particular file with a fixed strategy (say ours).

For instance, you have master (stable) and develop (unstable) branches. When code is stable you freeze the master, and development continues in develop, which is merged to master every few weeks.

But then you find our bugs at regression testing stage, you fix them in master, and you build. In the meantime, you also build develop separately. Each build bumps version field in package.json.

Since those branches can be built separately, a file like package.json will be modified in both branches, and there'll be a merge conflict due to version field being changed in both branches.

How to easily resolve the merge conflict in an automated manner (script) in such a situation?

git built-ins that do not solve the problem

  • git merge -Xours: that would resolve ALL conflicts in ALL files using the same strategy. This might be too much. (For instance, you might want to have an automatic merging script, which can do a successful conflict resolution only if foobar.json is the only file that was modified; on any other files modified, the merge should fail)

  • git checkout --ours filename.txt: that would discard ALL the changes from theirs version, which is brutal. There might be some valid, non-conflicting changes that would be discarded this way.

  • What we need is something like git-resolve-conflict --ours filename.txt

This is what ./lib/git-resolve-conflict.sh from this repo provides.

Details

See README-extended.md

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].