I am new to git, I am trying to revert back about 20 commits that are already committed to the master branch by someone else. I thought I could use got rebase and pick and chose which commits to revert and which ones to edit and which ones to leave. Is this not the case? Can rebase only be done in my local repo? Is there a way to go back 20 commits with one single script? Or does it have to be done with git revert each time? Thanks in advance
You can rework your feature branch however you see fit. git rebase -i HEAD~20
. An editor pops up where you d
rop those commits you want to drop and save. Finally to make the changes affect the remote: git push --force
.
And indeed, you should only do that if you're sure no-one else was using that remote branch, because you just removed commits from it and that would make it incompatible with other people's work on that same branch. If not you can use git revert
, which adds a commit that undos the changes by a previous commit.