Reputation: 1
My colleague has pushed some commits to our working branch by mistake and now I want to rollback to a previous commit both locally and remotely.
I use reset --hard to the selected commit, the HEAD in my local branch moves to the selected commit and then I use
git push -f origin working_branch:working_branch
to push the HEAD but I get denying non-fast-forward error.
How should I rollback to the selected commit both locally and remotely?
Thanks in advance!
Upvotes: 0
Views: 3365
Reputation: 3284
You can use git reset --hard HEAD~1 to remove the latest commit and then do
git push origin master --force
to push to the server
Upvotes: 1
Reputation: 2247
you can revert that commit with git revert
command - https://git-scm.com/docs/git-revert. git revert
creates another commit that reverts changes. Also pushing with --force
is not safe as you may override tree that someone already fetched.
Upvotes: 3