I created a "feature" branch off master and worked for a long while. I then fetched the latest master branch commits and rebased my "feature" branch commits on top of it. Then I merged "feature" into master. However, I forgot about the merge and continued committing into the "feature" branch. I want those commits in a new branch now, so I would now like to create another branch, "feature_2", that is based on the commits on the "feature" branch since the last merge into master. Any suggestions?
+1
A:
Considering that:
feature
already references commits since last merge intomaster
- branches are just pointers
x--x--x (master) \ y--y--y (feature)
, you can simply:
git checkout feature
git checkout -b feature2
git branch -f feature master
(provided no commits were made onmaster
since thefeature
merge)
x--x--x (master, feature) \ y--y--y (feature2)
All the commits from master are no longer referenced by feature
(which is reset to where master
is), but are now accessible through feature2
(which is where feature
is before being reset to master
)
The OP Chip Castle adds:
I have 3 other team members who have had their branches merged into master since then, so I don't want to merge the same commits I have already merged.
I was hoping to give a SHA range only for the commits I need from feature to a new branch. Is there any way to do that or a better way?
So the situation is:
x--x--x--y'--y' (master, updated after a fetch from other repo) \ y'--y'--y--y (feature, with y' being already merged, and y being the commits I need)
Then you can simply rebase feature on top of master: identical commits will be ignored.
VonC
2010-08-17 03:56:19
I have 3 other team members who have had their branches merged into master since then, so I don't want to merge the same commits I have already merged. I was hoping to give a SHA range only for the commits I need from feature to a new branch. Is there any way to do that or a better way?
Chip Castle
2010-08-17 13:22:29
@Chip: I have updated my answer, but don't hesitate to leave a comment here if I have misunderstood your exact situation, and edit your question with a diagram illustrating your current repo state if necessary.
VonC
2010-08-18 06:41:13
@VonC: Perfect. That works for me. Thanks!
Chip Castle
2010-08-21 01:30:25