subsub
subsub

Reputation: 1857

How to discard changes that are already pushed to remote?

I have found a couple of similar questions, and answers but those are only concerned about local commits (and answers sometimes say do not do this after sharing changes).

I have the following:

A-B-C-D-E (HEAD)
        ↑
      master = origin/master

What I want is this:

    someBranch
        ↓
    C-D-E (HEAD)
   /
A-B-F
    ↑
master = origin/master

Where F can be a commit saying that master has been reset there. Basically I want to undo the changes in C, D and E. but I don't care the reset is visible in the repository.

If this is not possible what are my closest alternatives?

Edit: To be clear: I am not the only one working on the project.

Upvotes: 2

Views: 1119

Answers (2)

devconsole
devconsole

Reputation: 7915

A very brutal solution would be to

git branch someBranch
git reset --hard HEAD~3
git push --force

This might be acceptable if you know that nobody else has pulled the branch since you pushed to, e.g. if you are the only one working on that project. Otherwise you will probably run into problems.

Upvotes: 2

gtr32x
gtr32x

Reputation: 2063

You can simply do git revert on all those commits and then just push upstream. It will revert all those commits.

Upvotes: -1

Related Questions