A commit is a saved snapshot with a message. Stage a file, commit it, make a change, and commit again. Then read your history.
Moves a file to the staging area. You choose what goes into the next snapshot.
git add todo.txt
Saves everything staged as one snapshot with a message.
git commit -m "message"
Write messages that finish the sentence "This commit will...": add todo list, not stuff.
Run git commit without -m and Git opens an editor so you can type the message. If you kept Vim as the editor, it looks like this, and typing does nothing. You are not stuck. Vim just needs keys.
Lines starting with # are hints. Git ignores them.
# Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # On branch main # Changes to be committed: # new file: todo.txt ~ ~ .git/COMMIT_EDITMSG [unix] 8L, 238B
Press i to type. Write your message on the first line. Press Esc, then type :wq and press Enter to save and finish.
Press Esc, then type :q! and press Enter. Nothing is committed. Next time add -m "message", or pick a friendlier editor in Chapter 5.
The screen above is an illustration rebuilt in the browser. Now try it for real:
Click the editor. You are in Vim. Typing letters does nothing yet. Try it, then use the buttons or your keyboard.
nothing added to commit but untracked files presentYou forgot git addStage the file first, then commit.Author identity unknownGit does not know your name yetDo the two git config lines from Chapter 5, then commit again.error: pathspec 'todo.txt' did not match any file(s) known to gitTypo, or wrong folderRun ls to check the file name and pwd to check the folder.Watch the three areas and the commit graph on the right.