Lesson 55 +15 XP

Snapshotting Commands

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

git add


bash
git add file.txt
git add .

Stages changes into the staging area.

git status


bash
git status
git status -s

Shows the state of the working directory and staging area.

git diff


bash
git diff
git diff - staged

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

git commit


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

Saves a snapshot of your staged changes.

git restore


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


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

Moves the branch pointer backward.

git rm and git mv


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.