Dimitra
Dimitra

Reputation: 1

git reset remote head

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

Answers (2)

Mohan Kumar P
Mohan Kumar P

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

krp
krp

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

Related Questions