git cat-file -p <oid> inspect any objectgit rev-parse HEAD resolve ref to OIDgit reflog history of where refs weregit switch -c feat create + move to branchgit restore --staged f unstage a pathgit fsck --lost-found find dangling objectsgit for-each-ref enumerate all refsThe Object Model (immutable content)
Git stores four object types in a content-addressed store; the SHA-1/SHA-256 of type + length + content is the object ID. Identical content is stored once.
| Object | Holds | References |
|---|---|---|
blob | Raw file bytes (no name, no mode) | nothing |
tree | Directory: mode, name, OID rows | blobs & subtrees |
commit | Tree OID, parents, author/committer, message | one tree + parents |
tag | Annotated tag: target, tagger, message | any object |
git hash-object -w filegit cat-file -t <oid>-s for size, -p to pretty-print.git write-treegit commit-tree <tree> -p <parent> -m msgRefs, HEAD & Reflogs (mutable pointers)
Refs are mutable names for OIDs living under refs/; HEAD is usually a symbolic ref to the current branch. Moving a ref and copying objects are separate operations.
git update-ref refs/heads/x <oid>git symbolic-ref HEAD refs/heads/maingit for-each-ref --sort=-committerdategit reflog show maincat .git/packed-refsgit rev-parse --symbolic-full-name @{u}git reset --hard HEAD@{1} rewinds to the previous position.Working Tree · Index · Reset Family
Three states: the working tree (files on disk), the index/staging area (a proposed next tree), and HEAD (the last commit). Most commands move data between these layers.
Staging plumbing
git update-index --add path registers a blob in the index; git ls-files -s dumps index entries with mode and stage.
Porcelain
git add -p stages hunks interactively; git status summarizes the diffs index↔HEAD and worktree↔index.
| Command | HEAD | Index | Worktree |
|---|---|---|---|
reset --soft <c> | moves | — | — |
reset --mixed <c> | moves | reset | — |
reset --hard <c> | moves | reset | reset |
restore --staged f | — | reset | — |
restore f | — | — | reset |
git switch <branch>git checkout <c> -- pathgit clean -fdnn to act).git stash push -u -m wipRevision Selection & Pathspecs
HEAD~3 / HEAD^2A..BA...Blog shows both sides.:/fix typomain@{2.days.ago}':(exclude)*.log'Attributes & ignores
.gitattributes sets text=auto, diff/merge drivers, filter (e.g. LFS); .gitignore excludes untracked paths, overridden by git add -f.
merge-base
git merge-base A B finds the common ancestor — the pivot for diffs, three-way merges, and rebase "what's new".