In the last lesson, you checked the history to see when the egg price last changed, and every answer came from a commit. Each of those commits is a snapshot of the project at that moment. When an edit goes wrong before you commit it, the last commit still holds the file the way it was.
In this lesson, you’ll try out an edit to the store’s opening hours that changes more than you meant and then get the file back exactly as it was committed. You’ll use the two commands that git status has been suggesting all along, and you’ll be able to say which one takes a file out of the staging area and which one throws your edits away. Start with an edit that takes a single click.
Make an Edit That Goes Wrong
The safest time to catch an unwanted change is before you commit it. First, check that the store’s repository has no other work in progress. In the store’s folder, run git status:
$ git status
On branch main
nothing to commit, working tree clean
That’s where the last lesson left the project. If your status lists changed files, read them with git diff and commit the changes you want to keep, as in the earlier lessons. That way, the tryout in this lesson can’t get mixed up with work you care about.
Say you want to see how the home page would look if the store stayed open an hour later on weekdays, until 10 p.m. from Monday to Friday, with Saturday’s hours unchanged. It’s only a tryout and isn’t on the README’s to-do list, so it won’t get in the way of your capstone.
The regular hours live in src/data/hours.js, one line per day of the week, with 24-hour times. The store closes at "21:00" Monday to Friday, so replacing all matches saves you from typing the new time for each weekday. Open the file in VS Code and press Ctrl+H, or Cmd+Option+F on macOS, to open the replace field. Type 21:00 in the find field and 22:00 in the replace field, click Replace All, and save the file.
Then look at the result. Open the home page in VS Code’s integrated browser, as in the setup lesson, and find the Opening hours table. Monday to Friday now read 7 a.m. to 10 p.m., which is the look you wanted.
You like it, so the tryout could become a real commit. Before you commit, follow the habit you built with git diff: stage the file and read what you’re about to record with git diff --staged: