在Git中重置后恢复磁头

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了在Git中重置后恢复磁头相关的知识,希望对你有一定的参考价值。

This snippet shows how to restore HEAD after using Git's reset method (see http://gitready.com/2009/01/17/restoring-lost-commits.html?disqus_reply=5271828#comment-5271828).
  1. # reseting
  2. $ git show-ref -h HEAD
  3. 7c61179cbe51c050c5520b4399f7b14eec943754 HEAD
  4.  
  5. $ git reset --hard HEAD^
  6. HEAD is now at 39ba87b Fixing about and submit pages so they don't look stupid
  7.  
  8. $ git show-ref -h HEAD
  9. 39ba87bf28b5bb223feffafb59638f6f46908cac HEAD
  10.  
  11. # the commit object still exists
  12. $ git fsck --lost-found
  13. [... some blobs omitted ...]
  14. dangling commit 7c61179cbe51c050c5520b4399f7b14eec943754
  15.  
  16. # showing the log of the old references of HEAD
  17. $ git reflog
  18. 39ba87b... [email protected]{0}: HEAD~1: updating HEAD
  19. 7c61179... [email protected]{1}: pull origin master: Fast forward
  20. [... lots of other refs ...]
  21.  
  22. # restoring HEAD back from the dangling ref object hash
  23. $ git merge 7c61179
  24. Updating 39ba87b..7c61179
  25. Fast forward
  26. css/screen.css | 4 ++++
  27. submit.html | 4 ++--
  28. 2 files changed, 6 insertions(+), 2 deletions(-)

以上是关于在Git中重置后恢复磁头的主要内容,如果未能解决你的问题,请参考以下文章

硬盘磁头损坏数据恢复方案

恢复片段后android地图停止响应

为啥片段恢复后再次调用onLoadFinished?

Homebrew修改源已经重置恢复

Homebrew修改源已经重置恢复

[git] 恢复删除的文件