I've executed the commands
git reset --hard 6eb7d13f32cf110a1122206e58df381c000a987e
git push --force
on my github repository. The problem is that the full SHA I used is incorrect. Now, my repository state is so old. So, I'm trying to revert the repository to the last commit I pushed before the execution of these two commands.
The output of a git reflog
is
6eb7d13 HEAD@{0}: reset: moving to 6eb7d13f32cf110a1122206e58df381c000a987e
4d0a0fd HEAD@{1}: pull: Fast-forward
82859b3 HEAD@{2}: commit: including command to install dependencies
e3c3ab8 HEAD@{3}: clone: from https://github.com/<user>/<repository>.git
The first output line points out the mistake I'd like to undo.
Is it possible to revert it? Thanks.
To get back to the state you were in just before the bad reset and push, reset and push again. The commit should still be there, unreferenced commits typically hang around for weeks. Looks like that's 4d0a0fd.
git reset --hard 4d0a0fd
Check everything is ok before pushing!
git push --force
This is why one should always hesitate before pushing, especially a force push. It gives you a moment to check everything is ok before sharing a mistake.