Reference

Git

Inspect, save, combine and recover work with clear command effects.

Scope and conventions

Modern Git CLI, including switch and restore (Git 2.23+). Independent examples use illustrative paths and branch names. Inspect status and diffs before changing files or history. Commands below are reference material, not executed by this guide.

Stage & save

Stage chosen content

Git

add copies current file content into the index. Later edits remain unstaged. add -p lets you review hunks.

Fragment

Git · Stage chosen content
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git add -- src/main.ts
git add -p
git diff --staged

Stage by intent; git add . can include unrelated work.

Remove a change from the next commit

Git

restore --staged restores the index from HEAD by default. The working file keeps its edits.

Fragment

Git · Remove a change from the next commit
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git restore --staged -- src/main.ts
git diff -- src/main.ts

Effect: index changes; working tree and branch history stay as they were.

Save the staged snapshot

Git

commit records the index as a new commit and advances the current branch. Unstaged changes and untracked files are not included.

Fragment

Git · Save the staged snapshot
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git diff --staged
git commit -m "Handle empty input"

Replace the latest local commit

Git

--amend creates a replacement commit from the current index, normally retaining the old message with --no-edit.

Fragment

Git · Replace the latest local commit
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
git add -- src/main.ts
git commit --amend --no-edit

Commit identity changes. Coordinate before replacing history already used by others.