At the end of the last lesson, the new notes file and your prices.js with its sweet potato line were both waiting in your practice folder under Changes to be committed. They’re in the cart, but they aren’t part of the history until you check out.
In this lesson, you’ll make that commit and confirm that it worked. Then you’ll run into a situation that surprises almost everyone who’s new to Git, and you’ll come away able to predict exactly what your next commit will contain. Start with the commit that’s already waiting for you.
Commit What You Staged
Staged changes are only a plan for the next commit, so Git doesn’t record them until you run git commit. Before you do, it’s a good habit to check what’s in the cart. Run git status in your practice folder:
$ git status
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: notes.txt
modified: prices.js
Both files are listed under Changes to be committed, so they’ll go into the commit. Use git commit with -m, as you did in the last lesson, and give the commit a message that tells a future reader what this change does:
$ git commit -m "Add practice notes and the sweet potato deal"
[main b823a4a] Add practice notes and the sweet potato deal
2 files changed, 4 insertions(+), 1 deletion(-)
create mode 100644 notes.txt
Git confirms the commit in a few short lines:
-
The first one lists the branch,
main, a short ID for the commit, called its hash, and your message. Your hash will be different fromb823a4a, because every commit gets its own. The same goes for every hash in this lesson. -
The second line counts the files and lines that changed since the previous commit. The two lines of
notes.txtand the sweet potato line are three insertions, and the rewritten comment counts as one deletion plus one insertion, because Git compares whole lines. -
The last line says
notes.txtis new to the repository. The100644describes the file’s permissions, and you can safely ignore it.
In the shopping cart picture, the commit is the checkout and the message is the receipt. To see the result of your checkout, ask Git for the status again and then for the list of commits with git log --oneline: