master から "feature" ブランチを作成し、長い間作業しました。次に、最新のマスター ブランチのコミットを取得し、その上に「機能」ブランチのコミットをリベースしました。次に、「機能」をマスターにマージしました。しかし、マージのことを忘れて、「feature」ブランチにコミットし続けました。これらのコミットを新しいブランチに入れたいので、マスターへの最後のマージ以降の「feature」ブランチでのコミットに基づいて、別のブランチ「feature_2」を作成したいと思います。助言がありますか?
1 に答える
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.