World map

 

BM: Baca dalam Bahasa Melayu

World 3: Parallel Universes · Boss challenge

Conflict Crusher

You will learn: to crush three conflicts and leave one clean history.

The problem

main and party both changed the diary. The merge stops with a red Conflict badge and a warning sign.
6d3a9b1a8feb63270a76efca27f021ab896d3bb4bc

Party mode meets your diary. Three conflicts! Then a messy branch to tidy. Ready to crush them all?

Watch

git merge party: CONFLICT in index.html and in style.css. git status lists both files as both modified. Terminal output: $ git merge party Auto-merging index.html CONFLICT (content): Merge conflict in index.html Auto-merging style.css CONFLICT (content): Merge conflict in style.css Automatic merge failed; fix conflicts and then commit the result. $ git status On branch main You have unmerged paths. (fix conflicts and run "git commit") (use "git merge --abort" to abort the merge) Unmerged paths: (use "git add <file>..." to mark resolution) both modified: index.html both modified: style.css no changes added to commit (use "git add" and/or "git commit -a")

Two files, three clashes. Read each one. Choose what stays. Mistakes are free, so experiment!

Try it

Crush all three conflicts. Title: keep yours. Day 5: keep both. Colour: keep theirs.

Pick what stays in each conflict. Then finish.

6d3a9b1a8feb63270a76efca27f021ab896d3bb4bc

Conflicts left: 3 of 3

index.html

<<<<<<< HEAD (conflict marker)
your line: <h1>My Git Diary</h1>
======= (conflict marker)
their line: <h1>Party Diary</h1>
>>>>>>> party (conflict marker)
<p>Day 1: I learned Git.</p>
<p>Day 2: I learned branches.</p>
<p>Day 3: I learned merging.</p>
<p>Day 4: I learned rebase.</p>
<<<<<<< HEAD (conflict marker)
your line: <p>Day 5: I fixed conflicts.</p>
======= (conflict marker)
their line: <p>Day 5: Party time!</p>
>>>>>>> party (conflict marker)

Check

Halfway through, you panic. Which command puts everything back to before the merge?

Pick one answer.

Try it

Four quick drills in the terminal. Each one starts fresh.

Step 1 of 4: Urgent switch

Dark mode is half done. Put it aside and go to main.

Working folder
Staging area
  • Empty
Repository
  • 4 save points
  • Start dark mode
  • Add style
  • Add day 1 page
6d3a9b1a8feb63270a76e2e1b6b1

Try it

Last one: the recipes branch. Fix up “oops” into the page. Rename “add cake” to “Add cake recipe”. Drop “temp debug”.

Each card is one commit. Pick an action. Drag the grip or use the arrows to reorder.

Top = oldest. Git replays the cards from the top down.

  • c276142 Add recipes page
    keep it
  • 5cc4c34 oops
    keep it
  • 3646b92 add cake
    keep it
  • f0886f8 temp debug
    keep it
  • 51b0794 Add pancake recipe
    keep it
History before Commits from newest: Add pancake recipe, temp debug, add cake, oops, Add recipes page, Add style, Add day 1 page, Add README.
6d3a9b1a8feb63270a76ec2761425cc4c343646b92f0886f851b0794

Check

You already shared the recipes branch. Mei built on it. Can you still tidy it with git rebase -i?

Pick one answer.

You did it!

You can now crush conflicts and keep your history clean.