0

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!

Dimitra
  • 1
  • 1
  • 3

2 Answers2

3

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.

krp
  • 2,247
  • 17
  • 14
1

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

Mohan Kumar P
  • 3,122
  • 1
  • 14
  • 17
  • This is what I tried first but git denied to push to the remote server. I got denying non-fast-forward error. – Dimitra Jul 05 '16 at 13:35