tags:

views:

202

answers:

1

I made 5 commits to Master branch when bug hunting on a private project and pushed them to the remote origin (my own private vps).

Then I saw that commits 4 and 5 were going to cause trouble elsewhere and I need to undo them, so I checked out commit 3 again, made a new branch "Dev" from that point, and did a few more commits fixing the issue properly.

Then I did

git reset --hard HEAD~2 on Master to pull it back to the point that I branched Dev.

Then I did git merge to fast forward Master back to the end of the Dev branch.

So now I have a local repository, with Dev and Master both pointing to the same, up to date version of the project with the latest bug fix.

Problem is, when I try to push the project now to the origin, it fails and gives me an error message:

! [rejected] master -> master (non-fast forward) error: failed to push some refs to 'myserver...myproject.git'

What have I done wrong, and how do I fix it?

Thanks

+2  A: 

It just doesn't like the fact that the branch you're pushing to isn't an ancestor of what you're pushing.

If you're certain you want to do that, just add the -f flag (force) to the push.

Tesserex
By "if you're certain" we mean: if this is a private project, if it's a public one but you know no one has pulled from this branch, or the mistake is so grievous that it's worth causing everyone else trouble to fix it this way instead of adding correcting commits.
Jefromi
It bears repeating: what you are doing is, you are rewriting history. And just like in real life, you *can* rewrite history, but you need a conspiracy in order to do that. IOW: everybody has to be "in" on it, i.e. everybody has to agree to rewrite history. (Where "everybody" means "everybody who ever pulled from the repository, even transitively".)
Jörg W Mittag
Thanks guys. I think I understand the implications. It's just a private project so no noe else will be messed up in this case.In the future though it wont come back to haunt me though will it...? As of now it's just a single branch of commits on Master, so a new contibuter wouldn't get the hassle of it in the future?