Question

I have a master branch that looks like this:

A-B- C -D-E-F
   \   /
    H-I

Where H and I are commits to the same branch made by another developer, and D is the commit from merging I and C. I want to remove all code from the commits H and I. I essentially want the branch to look like:

A-B-C-E-F

My plan was to do:

git rebase --onto C E
git push origin master --force

No other developers have branches or forks or anything that this would upset. Will these commands do what I want? I don't need the -p flag on the rebase do I?

Was it helpful?

Solution

I ended up using:

git rebase -i C

In the rebase a document will come up for you to edit, you delete the lines for the commits you want to remove (H and I). Then I had to fix a bunch of merge conflicts, and eventually call:

git push origin master --force

I was about 9 commits past the ones I wanted to remove and I had to merge 5 or 6 times, some times the same changes in the same file for whatever reason. This might not be a good answer if you are 100 commits down the line.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top