1

If I reset my last commit using git reset --hard HEAD^, how do I undo the reset?

I don't have anything more to ask, but apparently there are length requirements for this message. I'm just writing more here to pass the quality standards.

3
  • Hmmm...did you push the branch to the remote before doing this reset? Either resurrect the previous branch from another version, or else get ready to sift through the reflog. Commented Mar 13, 2017 at 13:39
  • Yup, it's a duplicate. Didn't see that one before.
    – nev
    Commented Mar 13, 2017 at 13:44
  • You should flag your flag this question as duplicated then
    – smarber
    Commented Mar 13, 2017 at 14:26

1 Answer 1

4

All changes that are not committed are lost. If it was committed, you can try git reflog to restore it.

This is already asked many times, so please see this one for reference.

4
  • His problem is because of an accidental git reset --hard not git rebase
    – smarber
    Commented Mar 13, 2017 at 14:23
  • reflog can be used, regardless of what kind of destructive operation Commented Mar 13, 2017 at 14:24
  • @TatsuyukiIshi If he nuked his working directory without having committed or stashed, the work really might be lost. Perhaps the IDE has a history feature in such a case. Commented Mar 13, 2017 at 14:26
  • I agree with you that the cure is the same, however the two questions are a bit different, rebase is not reset --hard. So your anwser is great to me except the part where you say This is already asked many times, a bit confusing I think
    – smarber
    Commented Mar 13, 2017 at 14:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.