How to Resolve Conflict In Git

Posted on the 31 March 2015 by Abhishek Somani @somaniabhi
Through a development life cycle when it comes to commit our whole day work and stuck in merge conflict without resolved/ No knowledge what went wrong in conflict makes our happiest day a dreadful night . Here are few tips which can save your dreadful night : Git merge Style Suppose you are on master and merging development :

$ git merge development
Auto-merging hello.rb
CONFLICT (content): Merge conflict in hello.rb
Automatic merge failed; fix conflicts and then commit the result.
We would like to see what the merge conflict is. If we open up the file, we’ll see something like this:

#! /usr/bin/env ruby
def hello
<<<<<<< HEAD
puts 'Hi Santosh'
=======
puts 'Hello Abhisehk'
>>>>>>> development
end
hello()
Both sides of the merge added content to this file, but some of the commits modified the file in the same place that caused this conflict. One helpful tool is git checkout with the ‘--conflict’ option. This will re-checkout the file again and replace the merge conflict markers. This can be useful if you want to reset the markers and try to resolve them again. You can pass –conflict either diff3 merge (which is the default). If you pass it diff3, Git will use a slightly different version of conflict markers, not only giving you the “ours” and “theirs” versions, but also the “base” version inline to give you more context.

$ git checkout --conflict=diff3 hello.rb
Once we run that, the file will look like this instead:

#! /usr/bin/env ruby
def hello
<<<<<<< ours
puts 'Hi Santosh'
||||||| base
puts 'Hello Santosh'
=======
puts 'Hello Abhisehk'
>>>>>>> theirs
end
hello()
If you like this format, you can set it as the default for future merge conflicts by setting themerge.conflictstyle setting to diff3.

$ git config --global merge.conflictstyle diff3
Keep Njoying GIT !!!! Thanks to Santosh for writing this post .