首先:是什么HEAD?HEAD只是对当前分支中当前提交(最新)的引用。任何给定时间只能有1个HEAD。如果您不在最新的提交上,这意味着它HEAD指向历史记录中的先前提交,则称为分离的HEAD。几种选择:git checkoutgit checkout <commit_id>git reflog您可以随时使用reflog,以及git refloggit checkout HEAD@{...}这将使您回到所需的提交git reset HEAD --hard <commit_id>将您的头“移动”回所需的提交。# This will destroy any local modifications.# Don't do it if you have uncommitted work you want to keep.git reset --hard 0d1d7fc32# Alternatively, if there's work to keep:git stashgit reset --hard 0d1d7fc32git stash pop# This saves the modifications, then reapplies that patch after resetting.# You could get merge conflicts, if you've modified things which were# changed since the commit you reset to.注意:(从Git 2.7开始),您也可以使用git rebase --no-autostash。git checkoutgit checkout -b <new branch> <commit_id>git checkout HEAD~X // x is the number of commits to go back这将签出一个指向所需提交的新分支这是可以完成的一般方案。