Restore Previous Commit Without Changing HEAD

Goal

Restore files from a previous commit to your working directory while keeping HEAD on the current branch (avoiding detached HEAD state).

Find the Target Commit

git log --oneline -n <N>

Restore Files from Previous Commit

git checkout <commit-hash> -- .

This command:

Without -- .: Git checks out the entire commit and enters detached HEAD state.