git cat-file -p <oid> inspect any objectgit rev-parse HEAD resolve a name to an OIDgit reflog recover "lost" commitsgit switch -c topic create & move to branchgit restore --staged f unstage without losing workgit fetch && git rebase integrate after transportgit fsck --lost-found find dangling objectsThe Object Model — Immutable Memories
Every state Git records is a content-addressed object whose name is the SHA-1/SHA-256 of its contents; change anything and you get a new object. The four types form a Merkle DAG.
| Object | Contains | Inspect |
|---|---|---|
blob | raw file bytes (no name) | git cat-file -p <oid> |
tree | names → modes → blob/tree OIDs (a directory) | git cat-file -p HEAD^{tree} |
commit | tree + parents + author/committer + message | git cat-file -p HEAD |
tag | annotated tag: target OID + tagger + message | git cat-file -p v1.0 |
git hash-object -w filegit cat-file -t / -s <oid>git write-treegit commit-tree <tree> -p <parent>Refs, HEAD & the Reflog — Pointers Into the Past
Refs are mutable names holding an OID; they make the immutable graph navigable. HEAD is usually a symbolic ref pointing at your current branch.
git update-ref refs/heads/x <oid>git symbolic-ref HEAD refs/heads/maingit for-each-ref --sort=-committerdategit reflog show maingit rev-parse --symbolic-full-name @{u}git pack-refs --all.git/packed-refs.git reflog remembers them until they expire (default 90 days).Working Tree, Index & State Transitions
Three trees: the working tree (files on disk), the index (staged next commit), and HEAD (last commit). Most commands move content between them.
Modern (intent-clear)
git switch <branch> changes branches; git restore <path> restores file contents. These split the overloaded checkout.
Classic & plumbing
git checkout still does both. git update-index --add is the plumbing behind staging.
| Command | HEAD | Index | Worktree |
|---|---|---|---|
reset --soft | moves | — | — |
reset --mixed (default) | moves | reset | — |
reset --hard | moves | reset | reset |
restore --staged | — | reset | — |
restore | — | — | reset |
commit --amend | replaces tip | — | — |
git stash push -ugit clean -fdnn to execute).reset --hard and clean -f discard uncommitted work that no object references — the reflog cannot save what was never committed.Revision Selection & Pathspecs
HEAD~3 / HEAD^2main@{2.days.ago}A..B / A...B:/fix typoHEAD:path/file-- ':(exclude)*.log'.gitignore controls untracked files; .gitattributes controls how tracked files behave (eol, diff, filter, merge, export-ignore). Both are policy, not part of the object graph's content rules.Integration — Merge, Rebase, Cherry-pick
Integration is separate from transport: these commands only rearrange the local graph by creating new objects and moving refs.
git merge-base A Bgit merge --no-ff topic