0

I forked a public github repository into a private github repository and cloned the code to several servers.

Today I accidentally pulled on one of the servers the new changes from the public fork and not from the private one. I did not notice my mistake right away and merged and pushed this polluted version to the private repository on github. How can I remove all the commits from the original origin, that are now polluting our branch.

I read around on SO and would

  1. rename the used branch on one of the other servers, that is unchanged. (git branch -m 'clean')
  2. delete the old branch on github and the local server (git push private_repo --delete <old_branch> and git branch -D <old_branch>)
  3. rename the local branch back (git branch -m <old_branch>_)
  4. push the clean version to github (git push private_repo <old_branch>)
  5. create patches from the commits, that I created on the server, where I did the wrong pull
  6. remove the local branch (git branch -D <old_branch>) and pull the cleaned branch from the private repo (git pull private_repo <old_branch>)

Is this the right way? Is there a less complicated and safer way?

[update]

I just stumbled upon https://stackoverflow.com/a/448929/380038

Can I just do:

  1. git push -f private_repo <old_branch> from one of the unpolluted clones

and than 5. and 6.?

They write in the answer, that push force does not delete commits, but just moves a pointer. Could this create issues, when I want to later pull commits from the original public github repo?

Community
  • 1
  • 1
Framester
  • 33,341
  • 51
  • 130
  • 192
  • You can maybe ask one of your colleagues to force push the latest copy of dev to your private repo. Specifically, if you can track who made the latest commit before you pushed, you could ask the same developer to force push and you can go from there. – gravetii Jan 14 '15 at 17:19
  • Thanks, the problem is, that the _main_ clone on github is _polluted_. – Framester Jan 14 '15 at 17:20
  • Yes, I understand. Let's call it the master branch. I believe at least a few of your colleagues would be having the latest uncorrupted master? – gravetii Jan 14 '15 at 17:22
  • I do have an instance of the latest uncorrupted branch, see point 1. I also rewrote the introduction, hopefully it is now better to understand. – Framester Jan 14 '15 at 17:28

0 Answers0