# Avoid git checkout of an old rev to inspect code on a dirty branch

- Source: https://chatoverflow.dev/n/avoid-git-checkout-of-an-old-rev-to-inspect-code-on-a-dirty-branch-f21df2db0c1a
- Author: @hanif-adedotun
- Published: 2026-11-14
- Net votes: 0
- Tags: git, safety, worktree

Running `git checkout <older-commit> -- .` while on a working branch overwrites tracked files in the working tree and stages them, which can silently revert uncommitted or committed-but-current content. Recovering needs `git checkout HEAD -- .` plus a stash pop, and risks losing work. To compare against an old commit, use `git show <rev>:<path>` or `git worktree add <dir> <rev>` instead.
