[英]How to move changes from a git remote branch to a new branch
I created my-feature-branch
branch from our develop
branch, committed my changes to it and raised a PR to merge it back to develop
.我从我们的
develop
分支创建了my-feature-branch
分支,提交了我的更改并提出了一个 PR 将其合并回develop
。
However, boss said, what I should have done is, created a my-feature-branch
from develop
, then created a my-story-branch
off my-feature-branch
, committed my changes to my-story-branch
and raised a PR to merge my-story-branch
back to my-feature-branch
.但是,老板说,我应该做的是,从
develop
创建一个my-feature-branch
,然后从 my-feature-branch 创建一个my-story-branch
my-feature-branch
,将我的更改提交给my-story-branch
并提出 PR将my-story-branch
合并回my-feature-branch
。
When all the stories of my-feature-branch
have been completed, then it will be merged back to develop
.当
my-feature-branch
的所有故事都完成后,它将被合并回develop
。
So, to fix this, I thought of doing like this:所以,为了解决这个问题,我想这样做:
my-feature-branch
again, and then create my-story-branch
off itmy-feature-branch
,然后创建my-story-branch
关闭它 Is there a shorter way to accomplish this without deleting branches and manually copy pasting my changes?有没有更短的方法可以在不删除分支并手动复制粘贴我的更改的情况下完成此操作?
EDIT :编辑:
what I did (current state of my git - changes have been pushed to remote)
------------------------------------
x-x-x (develop)
\
x-x' (my-feature-branch)
The above should now be changed to:
----------------------------------
x-x-x (develop)
\
x (my-feature-branch)
\
x-x' (my-story-branch)
And then raise a PR to merge my-story-branch to my-feature-branch
Since you have already pushed my-feature-branch
to the remote (assuming origin
) we should probably remove that.由于您已经将
my-feature-branch
推送到远程(假设origin
),我们可能应该删除它。 Make sure that no-one else is using that branch.确保没有其他人在使用该分支。
git push -d origin/my-feature-branch
# (if force has to be used)
# git push -f -d origin/my-feature-branch
We can rename the local my-feature-branch
to be my-story-branch
and push that.我们可以将本地
my-feature-branch
重命名为my-story-branch
并推送它。
git checkout my-feature-branch
git branch -m my-story-branch
git push origin my-story-branch
And because we still need my-feature-branch
to merge into, we can create that and push it too.因为我们仍然需要
my-feature-branch
来合并,所以我们可以创建它并推送它。
git checkout develop
git checkout -b my-feature-branch
git push origin my-feature-branch
A simplified git tree should look like this:简化的 git 树应如下所示:
x-x-x (develop)(my-feature-branch)
\
x-x-x' (my-story-branch)
Once my-story-branch
has been merged with my-feature-branch
it should look like this:一旦
my-story-branch
与my-feature-branch
合并,它应该如下所示:
x-x-x (develop)-x (my-feature-branch)(my-story-branch)
\ /
x-x-x'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.