Resolving a merge conflict

GIT, 2015-06-17 00:08:28 UTC

The GIT is something commonly use in the work related to software development. We often use these commands; git add, git commit, git push, git pull.

The conflict happens when you pull the repository because someone has changed the same file which you have committed to your local repository.

$ git pull
Auto-merging db/structure.sql
CONFLICT (content): Merge conflict in db/structure.sql
Automatic merge failed; fix conflicts and then commit the result.
$


The conflicting part begins with <<<< and ends with >>>>.

Open the db/structure.sql with your favourite editor. This example uses nano;

$ nano db/structure.sql



The db/structure.sql file;

  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL
 
<<<<<<< HEAD
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=16 ;
=======
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=100 ;
>>>>>>> 7440f2fcb9bb97566b1d71f419515e9e0e394179


Now you know which part is conflict. You have several options to resolve this. You can keep your changes, take someone changes or make a brand new change.

Above example changes into;

  `created_at` datetime NOT NULL,
  `updated_at` datetime NOT NULL
 
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=100 ;


Once you happy with the result or your collaborator happy with the result, you can add, commit and push into the repository.

$ git add db/structure.sql
$ git commit -m "resolve db/structure.sql conflict"
$ git push


That's it. Cheers!


Share: