Posted By

narkisr on 01/18/09


Tagged

Bash git


Versions (?)

Restoring HEAD after a reset in Git


 / Published in: Bash
 

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... HEAD@{0}: HEAD~1: updating HEAD
  19. 7c61179... HEAD@{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(-)

Report this snippet  

You need to login to post a comment.