Maryam
Maryam

Reputation: 1496

Undo a git merge when it has been pushed

How can I undo a merge when I have already pushed to master after merge? Here are my steps:

  1. git add -A

  2. git commit -m "some message"

  3. git fetch origin master:master

  4. git rebase master (resolve merge conflicts)

  5. git push -f origin my local branch

I want to go back to the state where i was at step 2

Upvotes: 0

Views: 1733

Answers (1)

intboolstring
intboolstring

Reputation: 7110

You force pushed, meaning you overwrote the changes on a remote. Your computer can't fix it; however, if there is another computer with a local copy before you force pushed, you can force push from that computer and overwrite your force push.

Git's push --force is destructive because it unconditionally overwrites the remote repository with whatever you have locally, possibly overwriting any changes that a team member has pushed in the meantime. - Atlaissan Git Resource

There are some cases where checking out to an old commit and then force pushing that might work, but I suspect that probably won't work in your case because you had to force push your changes.

Upvotes: 5

Related Questions