Creating merge conflict

Let's use the animal_farm/ repository we initialized earlier in this chapter as an example (or you can follow this with your own example if you have a merge conflict you're trying to resolve):

$ cd animal_farm/

We'll create an additional branch which will conflict with the master branch. In the animal-create branch, we'll rename a make_animal method to create-animal while, in the master branch, we'll change it to build_animal. The order of operations is important in creating the conflict, so you may want to follow closely.

We can start by creating a branch and editing animal_farm.py:

$ git checkout -b create-animal
$ vim animal_farm.py

Let's replace our make_animal method with create_animal:

...
def create_animal(kind):
...
animal_farm.add_animal(create_animal(animal_kind))
...

Now, commit the change:

$ git add animal_farm.py
$ git commit -m "Rename make_animal to create_animal"

We can now switch back to the master branch to make our next set of changes:

$ git checkout master
$ vim animal_farm.py

This time, we'll replace make_animal with build_animal:

...
def build_animal(kind):
...
animal_farm.add_animal(build_animal(animal_kind))
...

Commit the file:

$ git add animal_converter.py
$ git commit -m "Rename make_animal to build_animal"

It's time to merge the create-animal branch with master:

$ git merge create-animal

Uh-oh! A merge conflict:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.125.2