CH.07 · 12 MIN · PART 2

Save a snapshot.

A commit is a saved snapshot with a message. Stage a file, commit it, make a change, and commit again. Then read your history.

git addgit commitgit log
Two saved snapshots and a checked commit stamp01snapshot 02git commitSAVED!

add, then commit

two steps on purpose
add

Moves a file to the staging area. You choose what goes into the next snapshot.

git add todo.txt

commit

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.

If a strange text window opens

the Vim trap

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.

1

This is Vim

Lines starting with # are hints. Git ignores them.

2

Write the message

Press i to type. Write your message on the first line. Press Esc, then type :wq and press Enter to save and finish.

3

Or get out

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:

Mini-game: escape VimSave with :wqQuit with :q!
~
~
~

Click the editor. You are in Vim. Typing letters does nothing yet. Try it, then use the buttons or your keyboard.

When it goes wrong

real messages, plain meaning
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.

Practice: two commits

hands-on

Watch the three areas and the commit graph on the right.

1

Loading

practice terminal · bash-style

Quick check

1 / 3

Pick an answer.
Git, Visually · Parts 1 and 2 · English