search

Home  >  Q&A  >  body text

Git误提交导致代码库被清空,如何还原?

git add 的时候没仔细看,结果发现提交的版本中把整个仓库的文件给删除了
而且被我 commit + push 到远程服务器了,该怎么恢复啊,重新 add + commit + push 上传的速度太慢了
T。T

怪我咯怪我咯2810 days ago759

reply all(1)I'll reply

  • 巴扎黑

    巴扎黑2017-04-21 11:19:22

    You can directly go back to the last submission and then force push.

    #假定当前正位于该错误提交,而其父提交为正确的提交
    git reset --hard HEAD~
    git push -f

    Please note that using the git push-f parameter may cause pull conflicts for others on multi-person collaboration projects.

    If you are not sure which commit to revert to, you can use git reflog 查看头指针的变动历史,然后使用 git reset --hard <commit hash>.

    reply
    0
  • Cancelreply