Ali Faris
Ali Faris

Reputation: 18630

remove commit in the middle of a branch

I have branch develop, for every new feature I should make new branch based on the this branch.

I had two tasks so I wrote the first feature by starting new branch feature/Foo, after completing this feature I start writing the second feature but now I based the new branch on the feature/Foo branch. but the problem that I should start the second new branch from the develop branch and not feature/Foo branch

checkout this (what I did)

 A => B => C                 // develop branch
             => D            // feature/Foo branch
                   => E      // feature/Bar branch

what I should Have is this (what I'm trying to achieve)

 A => B => C                 // develop branch
             => D            // feature/Foo branch
             => E            // feature/Bar branch

now how could I remove the commit D from feature/Bar so that the branch start directly from the develop branch

Upvotes: 0

Views: 44

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 522646

One option is to use the two-argument form of rebase --onto:

# from feature/Bar
git rebase --onto C D

In plain English, the above says to give feature/Bar a new base, beginning at the commit whose parent is D (i.e. replace the E commit). This new base should be placed on top of commit C.

Note that this option rewrites history, and so should be avoided in the event that feature/Bar already be shared by multiple people.

Upvotes: 4

Related Questions