答案 0 :(得分:1)
您始终可以再次克隆项目以从存储库中获取最新代码。
另一种选择是执行fsck
并从悬空文件中恢复。
# Search for all uncommitted added files = dangling content
git fsck --full
# print out the content of the dangling content
git show <SHA-1>
如果提交内容,只需使用git reflog
更详细的信息可以在这里找到:
How to move HEAD back to a previous location? (Detached head)
单行命令,仅为了便于阅读而违反多行
# You can try recovering a branch by resting your branch to the sha
# of the commit found using a command like:
git fsck --full --no-reflogs --unreachable --lost-found |
grep commit | cut -d\ -f3 | xargs -n 1
git log -n 1 --pretty=oneline > .git/lost-found.txt
# Display the above commits
git log -p <commit>
# OR:
git cat-file -p <commit>