lab 30 Resolving Conflicts

Goals

Merge master to greet 01

Now go back to the greet branch and try to merge the new master.

Execute:

git checkout greet
git merge master

Output:

$ git checkout greet
Switched to branch 'greet'
$ git merge master
Auto-merging lib/hello.rb
CONFLICT (content): Merge conflict in lib/hello.rb
Automatic merge failed; fix conflicts and then commit the result.

If you open lib/hello.rb, you will see:

File: lib/hello.rb

<<<<<<< HEAD
require 'greeter'

# Default is World
name = ARGV.first || "World"

greeter = Greeter.new(name)
puts greeter.greet
=======
# Default is World

puts "What's your name"
my_name = gets.strip

puts "Hello, #{my_name}!"
>>>>>>> master

The first section is the version on the head of the current branch (greet). The second section is the version on the master branch.

Fix the Conflict 02

You need to manually resolve the conflict. Modify lib/hello.rb to be the following.

File: lib/hello.rb

require 'greeter'

puts "What's your name"
my_name = gets.strip

greeter = Greeter.new(my_name)
puts greeter.greet

Commit the Conflict Resolution 03

Execute:

git add lib/hello.rb
git commit -m "Merged master fixed conflict."

Output:

$ git add lib/hello.rb
$ git commit -m "Merged master fixed conflict."
Recorded resolution for 'lib/hello.rb'.
[greet 25f0e8c] Merged master fixed conflict.

Advanced Merging 04

git doesn’t provide any graphical merge tools, but it will gladly work with any third party merge tool you wish to use.

Table of Contents