1

I had a git accident.

I was working on a local branch "feature1"
I wanted to do "git push not-origin feature1:master"
instead I accidentally did "git push origin feature1:master".

It made a lot of mess and made the commits interleave (not that I can just revert a specific commit)

Is there any way to revert this considering I did not have an updated version of master locally so I can't just force push it?

PS: I did not find any way to block pushes to master without upgrading to Enterprise which is to expensive for this eature...

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
borod108
  • 766
  • 1
  • 6
  • 16

1 Answers1

4

Is there any way to revert this considering I did not have an updated version of master locally so i can't just force push it?

I think you are mistaken there; As long as you didn't do a forced push (a push with the --forced flag), the git push would have succeeded only if the remote refs lied on the path from current ref, i.e., your current branch did not diverge from your remote master branch.

This would mean that your branch feature1 has some commit C, which was what the master was pointing at.

So all you need to do is figure C out, create a new branch using git branch master_recovered C, and force push this branch to master using git push -f origin master_recovered:master.

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
  • 1
    Wow, I actually did not believe you at first, but it tested it with non conflicting commits on both branches and it still would not let me push as described in the question, you are right! Thank you! – borod108 Jan 20 '15 at 09:42
  • Thank you! I'd made a push -f from a detached branch and I was feeling terrible about it! but this fixed it! (for those who might be wondering how to get C, simply run 'git log') – mmbrian Oct 11 '15 at 01:27