Merge add-cats into main

❮ Back Next ❯

In this step, we will demonstrate a true merge with merge conflicts by merging the branch add-cats into main.

The reason that this will be a true merge, versus as fast-forward merge, is because main is not an ancestor of add-cats. Run the gloga command to confirm this fact.

The reason that there will be merge conflicts is that the routes.rb file was modified on both the add-dogs and add-cats branches, and their edits were made on essentially the same line of the file. Thus, Git will not be able to guess how the lines should be merged, resulting in a conflict.

You should already be on the main branch. (If not, switch to it.)

Merge add-cats into main:

git merge add-cats

You should see a lines like these ones among the output:

CONFLICT (content): Merge conflict in config/routes.rb
CONFLICT (content): Merge conflict in db/schema.rb

Note that this line indicates that the merge did not complete successfully, and a conflict must be resolved in the config/routes.rb and db/schema.rb files.

Run the git status command.

Note that it shows a list “Unmerged paths” that contains all the files in which there are merge conflicts that need to be resolved.

Open config/routes.rb in VS Code.

Note that annotation lines have been added to the file delineating the two conflicting versions of the code.

The lines will look similar to this:

<<<<<<< HEAD
  resources :dogs
=======
  resources :cats
>>>>>>> add-cats

Edit these lines such that both resources lines are kept (since we want to keep the routes for both dogs and cats) and all of the annotation lines (i.e., the ones beginning with <<<..., >>>..., and ===...) are deleted. Note that you can perform these edits by pressing the “Accept All Changes” button in VS Code. These edits should result in working code.

To resolve the merge conflict in db/schema.rb, we can simply reset the database, which will regenerate the file:

rails db:migrate:reset

Making the above changes should effectively resolve all the pending merge conflicts; thus, we can now complete the merge.

Stage all your changes and create a new commit:

git add -A
git commit

A default log message will be provided. To accept the default message, press Ctrl-X (to exit the editor), press Y (to confirm saving the log message), and press Enter (to confirm the location to save to).

Run the gloga command.

Note the new commit that was created that merged together two prior commits. Also, note that the commit history of main now includes all of the other three branches, fix-bug, add-dogs, and add-cats.

What to submit: Submit to the designated Canvas assignment a screenshot of your desktop that includes your terminal, showing the output of the above gloga command.


❮ Back Next ❯