Skip to content

Latest commit

 

History

History
242 lines (170 loc) · 6.89 KB

8-merge-conflicts.md

File metadata and controls

242 lines (170 loc) · 6.89 KB

Lab 8: Merge Conflicts

In this lab, you're going to resolve merge conflicts in the GitHub UI as well as the command line.

Scenario

Several teammates have made adjustments to the game to change the difficulty. It's up to you to review their pull requests, resolve any conflicts, and merge their changes!

Task 1: Merge the First Feature Change (GitHub UI)

In this task, you will merge the first feature change in the GitHub UI. After this, you will see that there is a merge conflict in the second pull request. You will resolve this conflict in the next task.

  1. In your browser, navigate to your repository on GitHub

  2. Click on the Pull requests tab

  3. Click one of the pull requests titled Increase the number of starting tiles

  4. Click the Files changed tab

    Note that this PR changes the number of starting tiles in the game.

  5. Click Review changes

  6. Select Approve

  7. Click Submit review

    You will be redirected back to the Conversation tab of the PR.

  8. Click Merge pull request

  9. Click Confirm merge

Task 2: Resolve Merge Conflicts (GitHub UI)

Now that the first PR has been merged, you'll see that the second PR has a merge conflict. In this task, you will resolve this conflict using the GitHub UI.

  1. Click on the Pull requests tab

  2. Click on the remaining pull requests titled Increase the number of starting tiles

    Note that the PR has a merge conflict in src/game_manager.ts.

  3. Click Resolve conflicts

    You will be directed to the conflict resolution page. There, you will see the changes introduced by the PR, as well as the current changes in the main branch (the ones you merged in the previous task).

      /** Start Tiles Count */
    <<<<<<< feature/start-tiles-3
      static startTiles: number = 4
    =======
      static startTiles: number = 2
    >>>>>>> main
    

    The <<<<<<<, =======, and >>>>>>> lines are conflict markers. The <<<<<<< line indicates the beginning of the conflicting changes, the ======= line separates the conflicting changes, and the >>>>>>> line indicates the end of the conflicting changes.

    To resolve the conflict, you need to choose which changes to keep and which changes to discard. In this case, you want to keep the changes from the PR and discard the changes from main.

  4. Delete the <<<<<<<, =======, and >>>>>>> lines

  5. Delete the changes from main (the static startTiles: number = 2 line)

    The updated lines should look like this:

    /** Start Tiles Count */
    static startTiles: number = 4
    
  6. Click Mark as resolved

  7. Click Commit merge

    You will be redirected to the Conversation tab of the PR. At this point, there should no longer be a merge conflict.

  8. Click the Files changed tab

  9. Click Review changes

  10. Select Approve

  11. Click Submit review

    You will be redirected back to the Conversation tab of the PR.

  12. Click Merge pull request

  13. Click Confirm merge

Task 3: Merge the Second Feature Change (Command Line)

In this task, you will merge the first pull request in the GitHub UI. After this, you will see that there is a merge conflict in the second pull request. You will resolve this conflict in the next task.

  1. In your browser, navigate to your repository on GitHub

  2. Click on the Pull requests tab

  3. Click one of the pull requests titled Increase rate of tiles with value 4

  4. Click the Files changed tab

    Note that this PR changes the rate that determines the value of new tiles.

  5. Click Review changes

  6. Select Approve

  7. Click Submit review

    You will be redirected back to the Conversation tab of the PR.

  8. Click Merge pull request

  9. Click Confirm merge

Task 4: Resolve Merge Conflicts (Command Line)

Now that the first PR has been merged, you'll see that the second PR has a merge conflict. In this task, you will resolve this conflict using the GitHub UI.

  1. Click on the Pull requests tab

  2. Click on the remaining pull requests titled Increase rate of tiles with value 4

    Note that the PR has a merge conflict in src/game_manager.ts.

  3. Open your local clone of the repository

  4. Pull the updates to the main branch

    git checkout main
    git pull
  5. Switch to the branch for the PR

    git checkout feature/tile-value-1
  6. Merge the main branch into the PR branch

    git merge main

    You will see a message similar to the following:

    Auto-merging src/game_manager.ts
    CONFLICT (content): Merge conflict in src/game_manager.ts
    Automatic merge failed; fix conflicts and then commit the result.
    
  7. Open src/game_manager.ts in your text editor

    You will see that the file has been updated to include conflict markers.

    static addRandomTile(): void {
      if (Grid.cellsAvailable()) {
    <<<<<<< HEAD
        const value = Math.random() < 0.1 ? 2 : 4
    =======
        const value = Math.random() < 0.5 ? 2 : 4
    >>>>>>> main
        const cell = Grid.randomAvailableCell()
    
        if (cell !== null) Grid.insertTile(new Tile(cell, value))
      }
    }
    

    The <<<<<<<, =======, and >>>>>>> lines are conflict markers. The <<<<<<< line indicates the beginning of the conflicting changes, the ======= line separates the conflicting changes, and the >>>>>>> line indicates the end of the conflicting changes.

    To resolve the conflict, you need to choose which changes to keep and which changes to discard. In this case, you want to keep the changes from the PR and discard the changes from main.

  8. Delete the <<<<<<<, =======, and >>>>>>> lines

  9. Delete the changes from main (the const value = Math.random() < 0.5 ? 2 : 4 line)

    The updated lines should look like this:

    static addRandomTile(): void {
      if (Grid.cellsAvailable()) {
        const value = Math.random() < 0.5 ? 2 : 4
        const cell = Grid.randomAvailableCell()
    
        if (cell !== null) Grid.insertTile(new Tile(cell, value))
      }
    }
    
  10. Add the change to the staging area

    git add src/game_manager.ts
  11. Commit the change

    git commit -m 'Merge main into feature/tile-value-1'
  12. Push the change

    git push

    The PR will be updated with the new commit that resolves the merge conflict.

  13. Navigate to the PR in your browser

  14. Refresh the page

    You should see that the PR no longer has a merge conflict.

  15. Click the Files changed tab

    Note that this PR changes the rate that determines the value of new tiles.

  16. Click Review changes

  17. Select Approve

  18. Click Submit review

    You will be redirected back to the Conversation tab of the PR.

  19. Click Merge pull request

  20. Click Confirm merge

Need Help?

If you're having trouble with any of the steps, you can ask for help in the meeting chat.