0

I did a mistake that is explained below:

I was on the branch feature5 which was around 200 commits forward compared to master, I created a local branch documentation from feature5. (I forgot I wasn't on master)

Then, I committed and pushed new/updated documents to origin/documentation (I thought the documentation branch didn't exists on origin. (Many projects... Lost my mind)

Then, I realized that I pushed in documentation about 200 commits that should not belongs to this branch. How can I revert it?

I took a look to this discussion, but I'm pretty lost in my documentation branch, I don't know where I should revert because there are too many commits from feature5 on it, I would like to revert the entire last push on this branch, is it possible? Or to know what was the last commit before my bad push?

Undoing a 'git push'

Another solution would be to delete the origin/documentation and create a new one based on master, because master contains the old origin/documentation branch without the bad last push, but I would like to try to keep the origin/documentation branch alive if possible. And who knows, maybe I'll need to do the same thing in a few days/weeks/months ^_^

I also took a quick look to git-revert but I don't see how it could help me so far.

Community
  • 1
  • 1
Vadorequest
  • 16,593
  • 24
  • 118
  • 215

1 Answers1

1

If I understand your problem correctly, you can fix this by rebasing your documentation branch on to master using the --onto parameter.

git rebase --onto origin/master HEAD~n

where "n" is the number of commits you actually care about in the documentation branch.

You will then need to use the -f flag when you push up your new documentation branch.

joshtkling
  • 3,428
  • 2
  • 18
  • 15
  • THe git rebase rollback `documentation` to the master HEAD, but I lost the last commit in the operation. – Vadorequest Feb 21 '14 at 17:32
  • I used `git cherry-pick 4de68af` to apply the commit lost to the `documentation` branch. Now I run `git push -f` and everything is ok. Thanks. – Vadorequest Feb 21 '14 at 17:36