Lesson 55 +15 XP

Snapshotting Commands

These commands handle staging, saving, and moving files in your repository.

git add

Code

bash
git add file.txt
git add .

Stages changes into the staging area.

git status

Code

bash
git status
git status -s

Shows the state of the working directory and staging area.

git diff

Code

bash
git diff
git diff - staged

Shows changes between versions. - staged previews the next commit.

git commit

Code

bash
git commit -m "Message"
git commit -am "Message"

Saves a snapshot of your staged changes.

git restore

Code

bash
git restore file.txt
git restore - staged file.txt

Discards working changes, or unstages files. The modern replacement for checkout file restores.

git reset

Code

bash
git reset - soft HEAD~1
git reset - hard abc123

Moves the branch pointer backward.

git rm and git mv

Code

bash
git rm file.txt
git mv old.txt new.txt

Remove a file from the repo, or move/rename it.

TL;DR

  • add and commit save snapshots.
  • status and diff show what is going on.
  • restore and reset undo or unstage changes.
  • rm and mv remove and rename tracked files.