Reputation: 6822
I have a DEV branch with a history looking like this (with each list item being a separate commit):
Suppose I want to "delete" feature 3 from this branch, but I don't want to lose the code in this feature so I want to put it in it's own separate branch.
Basically, from the dev branch above, I want to end up with two branches looking like this:
DEV BRANCH:
NEW BRANCH:
Any ideas how I can achieve this in git?
Upvotes: 1
Views: 81
Reputation: 405
Create a new branch from feature3
. Then reset
feature3
from the dev
branch. However, if you have pushed these commits you will need to use revert
First create newbranch
from feature3
git checkout dev
git branch newbranch feature3
git reset --hard feature3
Now if you haven't pushed to remote
git reset --hard feature3
Or if you have pushed
git revert feature3
Also, if you want to add specific commits to newbranch
, like feature7
you can use
git checkout newbranch
git cherry-pick feature7
Upvotes: 3
Reputation: 16763
To create a new branch till feature3
:
git checkout <feature3_commit_id>
git checkout -b new_branch
To remove feature3
from dev branch
git checkout dev_branch
git rebase --onto <feature2_commit_id> <feature3_commit_id> <feature5_commit_id>
Just FYI, you can use git log --oneline
to find commit ids.
Upvotes: 0
Reputation: 30958
#create NEW
git branch NEW commit3
#rewrite DEV
git rebase -i commit2 DEV
#in the editor remove the line "pick commit3", save and exit.
Upvotes: 0