[英]Git: Change branch I have branched off of
For a new feature I have created a branch in Git from the current dev branch (not master) and implemented some changes locally but without committing. 对于一项新功能,我从当前的dev分支(不是master)在Git中创建了一个分支,并在本地实现了一些更改,但未提交。 Then I got sidetracked, and development has moved on.
然后我被束缚了,开发继续进行。 The branch I used as a base has been closed now, and there's a new one.
我用作基础的分支现已关闭,并且有一个新分支。
How can I change my feature branch so it's using the new dev branch as a base? 如何更改功能分支,使其以新的dev分支为基础?
master --
\-- dev 1
\-- feature
\-- dev 2
I want to move feature now that it branched off to dev 2 and then commit my changes: 现在我想移动功能,因为它分支到了dev 2,然后提交了我的更改:
master ---
\-- dev 1
\-- dev 2
\-- feature
to the feature branch, without losing commits which others might have made, of course. 当然,在不丢失其他人可能做出的提交的情况下,也可以将其添加到功能分支。
You need to 你需要
git rebase dev1 feature --onto dev2
(If I remember the arguments correctly, you may need dev1^
but I dont believe so). (如果我没记错的话,您可能需要
dev1^
但我不相信)。
Looks like you have to add your changes that are not commited yet on top of the dev2
branch. 看起来您必须在
dev2
分支的顶部添加尚未提交的dev2
。 Please correct me if I'm mistaken. 如果我弄错了,请纠正我。
git stash save -u "My feature" # stash all changes
git branch -d feature # delete old feature branch
git checkout dev2
git branch -b feature # create new feature branch
git stash apply # unstash all you changes
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.