You can indeed switch to an intermediate project state, although you want to use git checkout 6aa32cf
instead of git reset --hard
; git reset
will move the HEAD branch to that state, which is not what you want. git will warn you that you're in a "detached HEAD" state, which means that it doesn't know which branch to advance when you commit. You can certainly still work and commit, though.
If you do make commits, and then checkout another branch without naming the branch you're on, git will warn you:
ash@autumn ~/code/peril ((9fae92d...)) $ git checkout master
Warning: you are leaving 1 commit behind, not connected to
any of your branches:
9fae92d Commit to find later.
If you want to keep them by creating a new branch, this may be a good time
to do so with:
git branch new_branch_name 9fae92d5d5698096f0c1ddc11773ffded1194af2
Switched to branch 'master'
Even if you don't follow its instructions, you can still find the commit later with git reflog show HEAD
and grep
if you remember the commit message you're looking for:
35f4222 HEAD@{0}: checkout: moving from 9fae92d5d5698096f0c1ddc11773ffded1194af2 to master
9fae92d HEAD@{1}: commit: Commit to find later.
0d4b27b HEAD@{2}: checkout: moving from master to 0d4b27b379
Or, even later, with git fsck --unreachable --no-reflogs
and some scripting.