Merge Conflicts

Note: For more general git documentation, check out our Git Reference.

It's very likely that when you pulled our stencil, Git reported a merge conflict. Merge conflicts are logged by Git with a line like CONFLICT: Merge conflict in src/main/resources/static/css/main.css (along with a bunch of other logs). A conflict occurs when two users of the same Git repo commit changes that are incompatible with each other.

For example: Imagine that the Refrigerator and the Toaster have cloned the same Git repo (from GitHub) onto their individual computers. They want to use this repo to store all sorts of important data about their efficiency, and in the beginning, the only file in this repository is a log file with a few items listed:

{item: 'fridge', date: '1/12/2097 0:00:00', temp: '42'}
{item: 'toaster', date: '1/12/2097 0:00:00', temp: '55'}

The Toaster makes the following change. Then the Toaster commits and pushes to GitHub:

{item: 'fridge', date: '1/12/2097 0:00:00', temp: '42'}
{item: 'toaster', date: '1/12/2097 0:00:00', temp: '55'}
{item: 'toaster', date: '1/12/2097 0:01:00', temp: '56'}

The Refrigerator hasn't pulled the Toaster's changes yet. He decides to make the following change and commit it:

{item: 'fridge', date: '1/12/2097 0:00:00', temp: '42'}
{item: 'toaster', date: '1/12/2097 0:00:00', temp: '55'}
{item: 'fridge', date: '1/12/2097 0:01:00', temp: '41'}

Now, when the Toaster goes to push his commit to GitHub, Git will tell him that he needs to pull first. The Fridge pulls and rebases off of the Toaster's changes, but now Git will point out a merge conflict (e.g. CONFLICT: Merge conflict in log.txt). Git isn't sure which change to accept. Should the third line be "{item: 'fridge', date: '1/12/2097 0:01:00', temp: '41'}" or "{item: 'toaster', date: '1/12/2097 0:01:00', temp: '56'}"? The Fridge must resolve this conflict manually. To do this, he opens log.txt to find this:

{item: 'fridge', date: '1/12/2097 0:00:00', temp: '42'}
{item: 'toaster', date: '1/12/2097 0:00:00', temp: '55'}
<<<<<<< HEAD
{item: 'fridge', date: '1/12/2097 0:01:00', temp: '41'}
=======
{item: 'toaster', date: '1/12/2097 0:01:00', temp: '56'}
>>>>>>> c1b340c563dc59b8f3816dce5598601a77d85009

Git adds both versions to the file separated by a ======= line and surrounded by <<<<<<< and >>>>>>> lines. The Fridge wants both items to be on the list, so he edits the file to become:

{item: 'fridge', date: '1/12/2097 0:00:00', temp: '42'}
{item: 'toaster', date: '1/12/2097 0:00:00', temp: '55'}
{item: 'fridge', date: '1/12/2097 0:01:00', temp: '41'}
{item: 'toaster', date: '1/12/2097 0:01:00', temp: '56'}

The Fridge owner kept both items and removed any artifacts left by Git. He can now add the file with git add log.txt. After all this, the conflict has been resolved, and the Fridge can commit and push his changes.

If you have a merge conflict in your main.css file, chances are it's very similar to this example. Just remove any lines added by Git, and be sure to keep any changes you've made along with any changes we made (specifically, we added some styling for the selected class).

Note: Git is complicated. Merging (and rebasing) can be a rather fragile operations. Don't be afraid to ask TAs questions about this section, and feel free to browse through Git documentation and other online resources!