I have made several commits to my local branch estimation
and pushed them to the remote branch estimation
.
Now, I want to remove the last 3 commits completely.
I tried to do git reset HEAD^
and git reset HEAD --hard
3 times but when I tried to push the changes, it complained about tip of the HEAD not aligned.
How do I do it?
EDIT:
The history looks like following:
commit e572aab4e18
commit e21e7310bc4
commit 4f372a513da
commit 31a4ac607ae
commit a1a6e3f02dd
I would like to remove top 4 and go back to commit a1a6e3f02dd
and make both local and remote branch on same HEAD.
If you already pushed the commits (and don't want to do a force-push and overwrite data in the remote repository, there are a couple things you can do):
You can use git revert
instead of git reset
:
$ git revert ~4..HEAD
Or you can use git checkout
and then commit the changes:
$ git checkout ~3 -- .
$ git commit
git revert
will do 3 separate revert commits. The git checkout
method will allow you to revert the changes in just one single commit.
In your case, you could do this:
$ git reset --hard $REMOTE/$BRANCH
$ git checkout a1a6e3f02dd -- .
$ git commit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With