Git disasters · Chapter 9 of 14

Line endings made every line change

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

  • Part: Rewriting history
  • 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.

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 commit that broke every line

    Since one pushed commit, every line of prices.csv and menu.txt shows as changed. One real price change is hidden in it. Find that commit.

    1. List the last few commits, with how many lines each one changed.

    2. Look at the commit that changed every line of both files.

    3. Show its diff again, but ignore the end of each line. Now you see the one real change.

    4. Write that commit's hash into answer.txt, in the case's folder.

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

  2. Task 2

    Fix: store the files with LF again, on GitHub

    Store prices.csv and menu.txt with LF line endings again, on GitHub. The bad commit is pushed, so do not change it. Fix it with a new commit.

    1. Make a rule that Git stores text files with LF.

    2. Ask Git to add the files it already tracks again, using the new rule.

    3. Make a new commit.

    4. Push main to GitHub. Use a normal push, not a force push.

    To pass: on GitHub's main, prices.csv and menu.txt have LF line endings (no carriage returns). prices.csv still has the line cutting-chai,30. menu.txt still has every dish. GitHub's main still has all the commits it had before.

  3. Task 3

    Guard it: a line ending rule the whole team gets

    Make sure every teammate's commits store text files with LF, from now on.

    1. Write a .gitattributes file. It tells Git to store text files with LF, whatever line endings the file has on the laptop.

    2. Commit it on main.

    3. Push it to GitHub.

    To pass: GitHub's main has .gitattributes. The Check then tries it in a copy of your repository, on main. It saves a new specials.txt and a changed prices.csv with CRLF (Windows) line endings and commits both. That commit must work, and Git must store both files with LF.

What you will learn

  • See what happened: find the commit that broke every line
  • Fix: store the files with LF again, on GitHub
  • Guard it: a line ending rule the whole team gets

More in Rewriting history

Build "Line endings made every line change" 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.