From the Git manual:
git checkout [--detach] <commit> Prepare to work on top of <commit>, by detaching HEAD at it (see "DETACHED HEAD" section), and updating the index and the files in the working tree. Local modifications to the files in the working tree are kept, so that the resulting working tree will be the state recorded in the commit plus the local modifications.
It seems there is only one option: HEAD detached. Can I specify an option not let HEAD detached?
[Upgrade 1] I asked a similar question in the comment in the post "Revert Git repo to a previous commit"
# To get just one, you could use `rebase -i` to squash them afterwards
# Or, you could do it manually (be sure to do this at top level of the repo)
# get your index and work tree into the desired state, without changing HEAD:
git checkout 0d1d7fc32 .
# Then commit. Be sure and write a good message describing what you just did
git commit
My Question to him: @Jefromi, after "git checkout 0d1d7fc32 .", is the HEAD already detached? Then "git commit" cannot do anything with the dangled HEAD.
to check out the state from 0d1d7fc32 in the current directory, but it leaves HEAD where it was. It's the same as using something like git checkout other-branch path/to/file - that will leave you on your current branch, and just check out the given file. In this case we're checking out the entire current directory instead of just one file, but still not changing HEAD. – Jefromi
So it seems we can let HEAD not attached by adding "."
[Update 2] From the answers and comments below, I think a neat one is: git reset --hard
But then now my question is: Is Jefromi's method correct?
git checkout 0d1d7fc32 .
git commit
See the above link for more details of his method.