learning-it by example

#179 AI coding and productivity 6.6 min

Git Merge Conflicts: Check Before You Accept a Fix

Three one-click resolutions left no conflict markers, and each one still failed a test.

1. In a file with a git merge conflict, which version sits between the first marker and the line of equals signs?
2. In the shipping-rule conflict, how many of the 3 tests did each one click resolution (keep ours, keep theirs, keep both) pass?
3. In the shipping example, why did keeping both sides still pass only 2 of the 3 tests, even though no line was lost?
4. In the git merge conflict checker (checks.py) for the shipping-rule file, what does the lost lines check do?
5. What is a limit of the lost lines check in the git merge conflict checker (checks.py)?

Practice only: nothing is saved and no score counts towards anything. Each answer comes with the reason.

  1. Read the conflict file

    Copy the code folder first. Git must be installed. Run python run.py file. Find the line that starts with seven less-than signs, the line of equals signs, and the line with seven greater-than signs. Say which value of FREE_FROM comes from main and which from the feature branch. When I ran it, the HEAD part had FREE_FROM = 40 and the other part had FREE_FROM = 50 and the member line.

    A hint

    The top part is HEAD, the branch you are on. The bottom part is the branch you are merging.

  2. Predict the five resolutions

    Before running anything, predict how many of the 3 tests each of the five resolutions passes. Then run python run.py check and compare. When I ran it, as is passed 0 of 3, ours, theirs and both each passed 2 of 3, and by hand passed 3 of 3.

    A hint

    As is still has markers, so the file cannot run as code.

  3. Write your own reason in the message

    In run.py, change the text of WHY to a reason of your own. Run python run.py commit and find your sentence on the Why line of the commit message. When I ran it with my own sentence, the Why line showed it, and the Kept from lines were unchanged.

    A hint

    The video says the why has to come from a person, not from the diff.

  4. Add a fourth test case

    In checks.py, add a fourth case to CASES: ((10,), {"member": True}, 4.99), which is a member who spends 10 and still pays shipping. Predict the tests column for each resolution, then run python run.py check. When I ran it, as is passed 0 of 4, ours 2 of 4, theirs 3 of 4, both 3 of 4 and by hand 4 of 4.

    A hint

    A member needs 25 or more for free shipping, so 10 pays the 4.99 fee.

These tasks are for you to try on your own machine. Nothing is checked or saved.

What this does not show

One tiny made-up conflict in a temp repo; no AI tool is run, the three tests are my reading of each branch's intent, and the lost-lines check compares whole lines only.

Up next in AI coding and productivity

More in AI coding and productivity

All AI coding and productivity videos

Related videos