Hacker News new | ask | show | jobs
by fragmede 518 days ago
Reflog is your friend.

    git break-my-shit
    git reflog
        ... output saying where you were before things broke
        ... grab the good commit sha
    git reset --hard good_commit_sha_from_reflog
2 comments

The copy-the-.git-dir trick works for worse issues than can be solved with a single reset --hard. Damn near anything, really, as long as you haven't touched any remotes. It also works if you don't remember/understand how you broke it, where it's broken, or which state you need to try to reset to.
And yet up above we have others recommending to never, ever, use `git reset --hard ...`.
The same people probably want to ban knives!