Reputation: 1975
I'm working with git on two different branches at the same time (ex feature/feature_1
and feature/feature_2
)
On feature/feature_1
, I started from the master, and I already pushed some commits (but not merged).
For feature/feature_2
, I wanted to start from master as well, but unfortunately, I started from feature/feature_1
, and I didn't notice it at the beginning, and I pushed some commits.
So on feature/feature_2
I have every commit from feature/feature_1
(that I don't want on this branch), plus some other commits that I want to keep.
How can I "remove" the commit from feature_1
that I have on feature_2
, without deleting the work I have already done on feature_2
.
I would point out that both branches are already pushed but are not merged yet, and have nothing in common.
Thanks
Upvotes: 1
Views: 114
Reputation: 30297
The easiest way:
git rebase --onto master feature/feature_1 feature/feature_2
That's it
Upvotes: 4
Reputation: 225172
Checkout feature_2
:
$ git checkout feature/feature_2
Do an interactive rebase against master:
$ git rebase -i master
Delete all of the commits you don't want on feature_2
in the editor that comes up, then save and exit.
You'll need to force push your branch if you need others to see the changes - this operation is changing history.
Upvotes: 1