简体   繁体   中英

Revert git push to wrong branch

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...

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, ie, 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM