Deleting a branch, amending a commit or overwriting a staged file deletes no objects. An object stays alive while it is reachable from a ref, HEAD, the index or a reflog entry (the log of where each ref has pointed, The Reflog); anything else is garbage, removed only after a grace period. Try an orphan blob and a deleted branch:
echo 'An orphan note' | git hash-object -w --stdin
git switch -q -c experiment
echo 'try something' > notes.txt && git add notes.txt && git commit -qm "Try an idea"
git switch -q main
git branch -D experiment
git fsck --unreachable --no-reflogs
git fsck --unreachable
git prune --expire=now
git fsck --unreachablea899a9a962fb3b7522e1f94fe7a14b4af144c94a Deleted branch experiment (was a863a72). unreachable tree 3fed2b02a92bc5d3f211a0dedbe2409af5d0170b unreachable blob 5a59be3fc709580ab81b143584bbd7c41786bdab unreachable blob 8cd05cc998db3ba634e94ab333fd0de70503d5cd unreachable commit a863a72b094fb7503e46613e6a2f8e0e15905f58 unreachable blob a899a9a962fb3b7522e1f94fe7a14b4af144c94a unreachable blob 8cd05cc998db3ba634e94ab333fd0de70503d5cd unreachable blob a899a9a962fb3b7522e1f94fe7a14b4af144c94a unreachable blob 8cd05cc998db3ba634e94ab333fd0de70503d5cd
Ignoring reflogs, the deleted branch's commit, tree and blob are unreachable; counting them, they are safe, because HEAD's reflog remembers the commit. prune --expire=now removed the loose orphan, while 8cd05cc waits in the cruft pack. By default unreachable objects are deleted after two weeks (gc.pruneExpire), and reflog entries expire after 90 days, or 30 for commits no branch contains (gc.reflogExpire, gc.reflogExpireUnreachable). Commands such as commit run git gc --auto, which acts only past thresholds, so a lost commit survives at least 30 days. Never run git prune --expire=now where you might still need one.