Git without fear · Chapter 3 of 28

What changed?

By the end of this chapter you can see exactly what changed, line by line, and commit only the change you mean to. Build it in your browser: a real editor and terminal, AI that explains, and tests that tell you when it works.

  • Part: Day one
  • 4 tasks
  • Git
  • In the all labs plan

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

Why you need this

Bunty had a busy morning. "I changed the cutting chai price like Meera asked," he says, "and a couple of other small things." He has committed none of it. Meera approved one change only: cutting chai from 25 to 30. Kabir wants that in a commit today, and Bunty's other small things left where they are until he explains them.

From the last chapter you know git status, git add and git commit. git status names the changed files but not what changed in them, and git add . or git commit -a would sweep all three files into one commit: an unapproved menu item and a debug line would go out with the price.

What you build: 4 tasks

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

  1. Task 1

    Read Bunty's changes line by line

    Bunty changed three files. See what he changed inside them before you save anything.

    1. Run git status. It lists the three changed files.

    2. Run git diff. It shows each changed line: - for a line that goes, + for a line that comes.

    3. You can also give git diff one file name, to see only that file.

    To pass: you ran git diff (without --staged) in the chapter folder. A command with a typing mistake does not count, so type it again.

  2. Task 2

    Commit only the cutting chai price

    Only the new cutting chai price is approved. Save just that change.

    1. Stage only prices.csv with git add.

    2. Run git status -s. prices.csv has its letter in the left column. The other two files have theirs in the right column.

    3. Commit with a message about the cutting chai price.

    To pass: there are exactly two commits: Add the menu, prices and order code, then yours. Your commit changes only prices.csv, and its prices.csv has Cutting chai,30.

  3. Task 3

    Keep Bunty's other changes as they are

    Bunty's changes to menu.txt and orders.js are not approved. Keep them in the files, but do not commit them.

    1. Do not undo, edit or commit menu.txt or orders.js.

    2. After your commit, run git status. It lists only those two files as modified.

    To pass: menu.txt still has the Bunty special line and orders.js still has the bunty was here line, in the files and not in a commit. Only these two files may differ from your last commit. Staged or not does not matter.

  4. Task 4 · interview question

    Interview: see what the next commit will save

    Interview question: how do you see exactly what the next commit will save, before you commit?

    1. Stage prices.csv first (task 2).

    2. Run git diff with the --staged option (or its other name, --cached).

    3. It shows only the cutting chai line changing.

    To pass: you ran git diff --staged (or git diff --cached) in the chapter folder. A command with a typing mistake does not count, so type it again.

What you will learn

  • git diff: every change you have not staged yet, line by line.
  • Staging one file: git add with a file name, and reading git status -s.
  • git diff --staged: exactly what the next commit will contain.

More in Day one

Build "What changed?" yourself

Your first week on Tapri’s team, and every Git situation it throws at you. 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 without fear are free. This one comes with the all labs plan.