Git disasters · Chapter 13 of 14

A conflict resolved wrongly

Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.

  • Part: Merges and detective work
  • 3 tasks
  • Git
  • In the all labs plan

The first 2 chapters of Git disasters are free. This one comes with the all labs plan.

Why you need this

git log -- <file> simplifies history: at a merge it follows only a parent the file matches, so the merge and the other side's commits can vanish from the list. git log -S<text> (commits where the count of that text changes) skips merges' own changes unless asked:

$ git log --oneline -- config.txt
fc4b41d Mark shipping for the sale
03c0756 Add a sale
66f25a2 Set shipping
$ git log -S"= 40" --oneline
8c29f2d Lower shipping to 40
$ git log -S"= 40" -m --first-parent --oneline
86e424f Merge branch 'sale'
8c29f2d Lower shipping to 40

--first-parent follows main's own line, and -m shows each merge as a diff against its first parent, so the merge that removed = 40 appears. git diff 86e424f^1 86e424f shows what the merge did to main.

What you build: 3 tasks

Each task has tests. You write the code in the lab's editor and press Check.

  1. Task 1

    See what happened: find the merge that dropped the fix

    Ravi's Monday fix made bill.js round the total with Math.round. It is not on main any more. Find the commit that removed it.

    1. Search the history for commits that added or removed the text Math.round.

    2. A plain search hides merges. Search again along main's own line, and show merges as diffs too.

    3. The commit that removed Math.round is a merge. Write its hash into answer.txt, in the case's folder.

    To pass: answer.txt has the hash of that merge commit (7 characters or more), and no other hash.

  2. Task 2

    Fix: both changes in bill.js, on GitHub

    Put Ravi's rounding back in bill.js, and keep Bunty's combo discount. Main is pushed, so fix it with a new commit on top.

    1. Change bill.js on main. Keep comboDiscount and its use in the total. Round the total with Math.round, not down.

    2. Run node --test.

    3. Commit on main, then push. Use a normal push, not a force push.

    To pass: on GitHub's main, a 30 rupee order bills 32 (31.5 with GST, rounded). A masala chai with a samosa (60, minus 10 for the combo, plus GST: 52.5) bills 53. node --test passes there. GitHub's main still has the commit "Add kesar chai to the menu".

  3. Task 3

    Guard it: Git remembers the right resolution

    Make Git remember the right way to fix this conflict, so it fixes it the same way next time.

    1. Turn on rerere in this repository.

    2. Check out the merge's first parent, as a detached HEAD.

    3. Merge the merge's second parent again. The same conflict appears.

    4. Fix bill.js the right way: combo discount and Math.round. Add it and commit. Git says it recorded the resolution.

    5. Switch back to main.

    To pass: the Check redoes the same merge in a copy of your repository. bill.js must come out with no conflict markers, and with Math.round and comboDiscount(items) both in it.

What you will learn

  • See what happened: find the merge that dropped the fix
  • Fix: both changes in bill.js, on GitHub
  • Guard it: Git remembers the right resolution

More in Merges and detective work

Build "A conflict resolved wrongly" yourself

Bunty is Tapri's new junior developer, and Kabir keeps handing you the Git incidents left behind. Each is a disaster interviews love to ask about. A real editor and terminal in your browser, AI that explains, and a Check that says when it works.

The first 2 chapters of Git disasters are free. This one comes with the all labs plan.