0

I need to remove code from my master branch...
Currently, it looks like this:
A->B->C->D->E->F

and i want to remove commits B to E, turning it to:

A->F

I tried to revert back to A and cherry pick F but it won't allow me to push because the tip of the branch is behind the remote counterpart...

How can I do this?

Leonardo
  • 10,737
  • 10
  • 62
  • 155
  • I'm going to state the obvious here, just in case you missed it. If you reset your branch back to A, then cherry-picked F on top of it, and did this with the same branch that originally had A-F, then you're going to *lose* B-E. Unless they also exist on other branches, they will be lost, gone, deleted, missing afterwards, changes introduced in these commits will not be present in F. **Is this what you want?** – Lasse V. Karlsen Jan 14 '19 at 21:06
  • yes, and i have B->E on another branch... – Leonardo Jan 14 '19 at 21:08
  • Some more control questions, 1) Do you have a backup, and 2) Are you the sole developer on this project? – Lasse V. Karlsen Jan 14 '19 at 21:09
  • 2
    If the answer to those questions are both yes, and if git fetch + git status now tells you that you're 5 commits behind upstream, and 1 commit ahead of upstream (5 because you are missing B-E and the *original* F, and 1 ahead because you have a *new* F, same changes but different parent), then you can do a force-push with `git push -f`. This will adjust the branch on the remote as well to be similar to what you have locally, without B-E. **Be aware that if this repository have been cloned by others, they will need to do some work, such as cloning again or perhaps repeating your actions.** – Lasse V. Karlsen Jan 14 '19 at 21:11
  • 1
    tks @LasseVågsætherKarlsen it worked as expected, pls post as answer so i can accept it – Leonardo Jan 14 '19 at 21:12
  • @LasseVågsætherKarlsen they won’t be lost. Just unreachable. An easy way to “backup” those commits would be to create a branch before the reset. – evolutionxbox Jan 14 '19 at 22:39
  • It takes git about 30 days to delete objects and commits. – evolutionxbox Jan 14 '19 at 22:47

0 Answers0