Git – Resolve merge conflicts

      No Comments on Git – Resolve merge conflicts

Many time, when we do git push/pull or git merge, we end up with conflicts.
In most case, solution to merge-conflicts is as simple as discarding local changes or remote/other branch changes.

Following is useful in those cases

Resolve merge conflicts

Search for all conflicting files.

grep -lr '<<<<<<<' .

Command above will list all files which has marker “<<<<<<<”

Resolve easy/obvious conflicts

To accept local/our version, run:

git checkout --ours PATH/FILE

If the solution is to accept remote/other-branch version, run:

git checkout --theirs PATH/FILE

If you have multiple files and you want to accept local/our version, run:

grep -lr '<<<<<<<' . | xargs git checkout --ours

If you have multiple files and you want to accept remote.other  version, run:

grep -lr '<<<<<<<' . | xargs git checkout --theirs

For complex conflicts

For files that need manual review/edit, use vim or any text editor to resolve differences.

 

Leave a Reply

Your email address will not be published. Required fields are marked *