Git has three useful views of your work: the current commit, the index (staging area, the proposed next snapshot), and the working tree (the files on disk). An edit can differ between each pair.
current commit ── staged difference ── index ── unstaged difference ── working tree
Start by observing, not changing anything:
git status
git diff
git diff --staged
git log --oneline --decorate -5
git diff shows tracked, unstaged differences against the index; git diff --staged compares the index with the current commit. Neither shows the contents of an ordinary untracked file: open it separately. git status lists untracked paths as well as staged and unstaged changes. Commit IDs in the log identify recorded snapshots; git show <commit-id> inspects a chosen commit after replacing the placeholder with an actual ID.
| Situation | Starting choice | Consequence |
|---|---|---|
| A file edit has not been committed | Restore a path | Can unstage without removing the working edit, or discard an unstaged edit deliberately. |
| A recorded change is shared | Revert | Adds a correction commit; existing commits remain. |
| An unshared branch tip needs revision | Reset | Moves the branch; the mode decides what happens to staged and working content. |
| A previous committed tip seems missing | Inspect the reflog | May locate a local earlier tip, not a guaranteed backup. |
| Private work needs a newer base | Rebase | Replays commits with new identities; not a generic undo. |
A branch named for one person can still be shared. If anyone may have based work on its commits, coordinate rather than rewriting them casually. Check git status for an operation already in progress and resolve or abort that operation using its own instructions before choosing another correction. Back up uncommitted or untracked work outside the repository when its loss would matter.