Reputation: 375
I wanted to delete the last 4 pushed commits so I did
git revert HEAD~4..HEAD
Now, the first commits of my repo are gone (I don't know how many commits are deleted). Is there a way to undo what I did?
I tried to do
git reset --hard HEAD^
and I got this error
fatal: Could not reset index file to revision 'HEAD^'.
Upvotes: 1
Views: 598
Reputation: 44908
This should show you the commits that haven't been garbage-collected yet:
git log --all --graph --oneline --decorate
You can checkout the branch that you want to "fix":
git checkout branchInWeirdState
then reset --hard to one of the commits from the history:
git reset --hard 23456787654
Something along those lines...
Upvotes: 1
Reputation: 1406
git revert
does not modify history. It creates a new commit that undoes the changes from the specified previous commits.
I don't know why git reset --hard HEAD^
is producing an error, but you might be able, as an alternative, to get the commit hash for the previous commit using git log
and git reset --hard <ref>
to that.
Upvotes: 0