2

I am working on a branch called Lion, I mistakenly done this:

git push origin lion:master

instead of

git push eng lion:master

Basically the second line is for pushing the lion branch to a staging heroku app but I mistakenly merge all my code to into origin master.

How can I revert than? I have about 200 commits in my branch.

Greg

Gregory
  • 557
  • 6
  • 17
  • See if you find anything helpful in [this](http://stackoverflow.com/questions/179123/how-do-i-edit-an-incorrect-commit-message-in-git), one of the most popular SO questions of all time (at least up until now) – DOK Apr 08 '12 at 18:16

2 Answers2

2

Assuming no-one else has already gone and got the new changes:

1) If you have direct access to the origin repository, you can do a git reset --hard <commit ID> on the relevant branch in origin.

2) Alternatively, you could do a git push -f with the old commit ID perhaps.

Stuart Golodetz
  • 20,238
  • 4
  • 51
  • 80
1

The command 'git reset' takes an optional commit argument. So, if you have access to the origin repository you could try:

git reset [--soft | --mixed] <last-good-commit>           # in the remote/origin repository

If you don't have access to the repository you should be able to do:

git checkout -b rework <last-good-commit>
git push origin rework:master                                   # The push merge will produce a commit that works back to <last-good-commit>
GoZoner
  • 67,920
  • 20
  • 95
  • 145
  • 1
    I get "! [rejected] rework -> master (non-fast-forward) error: failed to push some refs to 'git@github.com:....' To prevent you from losing history, non-fast-forward updates were rejected.... – Aneil Mallavarapu Aug 09 '12 at 20:48