wrahim
wrahim

Reputation: 1168

Remove commits from remote without force pushing

I need to reset the origin/branch to 2 commits back:

a---b---c[head]---d---e[origin/branch]

to

a---b---c[head, origin/branch]

However I can't force push to this branch as it is protected on github.

What is the procedure to basically erase the last two commits from remote (github)?

Upvotes: 2

Views: 1298

Answers (1)

Craig Siemens
Craig Siemens

Reputation: 13276

A force push is the only way to remove commits. However you can create a new commit that undoes what what changed in previous commits using git revert.

In your case, to undo the changes from commits d and e, you would do

git revert d e

Then you just need to commit the changes and push to origin.

Upvotes: 4

Related Questions