Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge code and resolve conflicts more easily using git?

There is a great option --patch which can be used with git add.

Using this option I can easily review all my changes and decide which chunks should be added to staging area. This interactive process can be made through all modified files.

I am looking for something similar for resolving conflicts. After rebase or merge you will often get list of both modified files.

Is there any command which:

1) will help me iterate through all this both modified files? This is very annoying when I have to copy every path to file to manually open it.

2) will resolve all conflicts automagically always using HEAD/main version?

like image 360
noisy Avatar asked Jul 08 '11 09:07

noisy


People also ask

What is a merge conflict in Git and how can it be resolved?

You can resolve merge conflicts using the command line and a text editor. MacWindowsLinux. Merge conflicts occur when competing changes are made to the same line of a file, or when one person edits a file and another person deletes the same file. For more information, see "About merge conflicts."

How the merge conflicts will come in Git?

Git can handle most merges on its own with automatic merging features. A conflict arises when two separate branches have made edits to the same line in a file, or when a file has been deleted in one branch but edited in the other. Conflicts will most likely happen when working in a team environment.

How do you auto resolve merge conflicts?

Resolving merge conflicts automatically If you are already in a conflicted state and want to give the preference to the work of other developers in all the conflicting files, then run the git checkout and git add commands: git checkout --theirs .


3 Answers

You should have a look to the git mergetool that should be of help resolving conflicts through command line.

like image 143
greydet Avatar answered Nov 08 '22 08:11

greydet


After years of searching, I finally found solution to my problem! It is not perfect, and for sure this is not resolving all my problems, but definitely this speeds up my work!

It is called git imerge (incremental merge).

At first, this is a little overwhelming and seems complicated, but the idea standing behind incremental merge is very simple.

For sure, you should take a look on git-imerge presentation from the GitMerge 2013 conference (20 min).

If you prefer read text, here is git-imerge: A Practical Introduction

like image 24
noisy Avatar answered Nov 08 '22 09:11

noisy


Try p4merge. You can easily configure it to work with mergetool and interactively choose which version do you prefer.

like image 39
takeshin Avatar answered Nov 08 '22 08:11

takeshin