Discard changes you do not want to keep. The hard reset will discard any uncommitted changes that you made in detached HEAD state:
git reset --hard
(如果没有这个,第3步将失败,抱怨分离的HEAD中修改了未提交的文件。)
看看你的分支。通过检查您之前处理的分支退出分离的HEAD状态,例如:
git checkout master
Take over your commits. You can now take over the commits you made in detached HEAD state by cherry-picking, as shown in my answer to another question.
git stashgit checkout master # Fix the detached head stategit stash pop # Or for extra safety use 'stash apply' then later# after fixing everything do 'stash drop'
git fetchgit branch -f master origin/master -- err yeah don't just ignore what's been going on remotely - eg point my master at the real mastergit merge master -- merge the changes into my local branch
git stash # Temporarily shelves (or stashes) changesgit branch # Find your default branchgit switch master # Point HEAD to master or main branchgit stash pop # Apply all the changes you had previously