Fixes T10037. When we're building commit aabbccdd, we currently do this to check it out:
git reset --hard aabbccdd
However, this has an undesirable side effect of moving the current branch pointer to point at aabbccdd. The current branch pointer may be some totally different branch which aabbccdd is not part of, so this is confusing and misleading.
Instead, use git reset --hard HEAD to get the primary effect we want (destroying staged changes) and then git checkout aabbccdd to checkout the commit in a detached HEAD state.