Use last commit hash instead of HEAD

The symbolic ref HEAD is not always available.