Bootstrap FreeKB - Git (Version Control) - Resolve merge conflict
Git (Version Control) - Resolve merge conflict

Updated:   |  Git (Version Control) articles

Let's say you have cloned a repository and there are two branches, master and feature/development and you are on the feature/development branch.

~]# git branch --all
* feature/development
  master
  remotes/origin/HEAD -> origin/master
  remotes/origin/feature/development
  remotes/origin/master

 

And you issue the git pull origin master command, and there are merge conflicts. Notice that each of these merge conflict have a different reason:

  • modify/delete
  • content
  • add/add
~]$ git pull origin master
From ssh://git.example.com:7999/myrepo
 * branch            master     -> FETCH_HEAD

CONFLICT (modify/delete): example.yml deleted in HEAD and modified in a0d52bf8805449e35907acd6f9979f015b5a7f4a. Version a0d52bf8805449e35907acd6f9979f015b5a7f4a of example.yml left in tree.

Auto-merging foo.yml
CONFLICT (content): Merge conflict in foo.yml

Auto-merging bar.yml
CONFLICT (add/add): Merge conflict in bar.yml

Automatic merge failed; fix conflicts and then commit the result.

 

For the files that have conflict "modify/delete" this means the file may have been modifed in the master branch and deleted in the feature branch. If the file is no longer needed, it can simply be deleted in the master branch.

For the files that have conflict "content", which is foo.yml in this example, the file should have something like this. This is basically trying to show you the conflict between the file in the feature branch vs. origin.

~]$ cat foo.yml
<<<<<<< HEAD
hello
=======
world
>>>>>>> a0d52bf8805449e35907acd6f9979f015b5a7f4a

 

One way to fix this is to update the files to be identical in the feature and master branches. It almost always makes sense to update the file in the feature branch. You may need to create a new commit with the -i flag which is used to stage the commit.

git commit -i -m "resolved merge conflict" foo.yml

 

Be aware that if there are 2 or more files, you may need to do the staged commit for all files together.

git commit -i -m "resolved merge conflict" foo.yml bar.yml

 

And then try the git pull origin master command again.

git pull origin master

 

And git push origin HEAD.

git push origin HEAD

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter e0c62f in the box below so that we can be sure you are a human.