[英]I branched off the wrong branch, how do I move my changes to correct branch?
We have a develop
branch and a release
branch.我们有一个
develop
分支和一个release
分支。
I was asked to make a change, but was later told that the change had to be a hotfix and so I should have branched off the release
branch.我被要求进行更改,但后来被告知更改必须是修补程序,因此我应该分支出
release
分支。
The current situation is this (I drew the diagram myself):目前的情况是这样的(我自己画的图):
I really don't want to loose all my work that is currently sitting on my feature-branch
.我真的不想放弃目前在我的
feature-branch
上的所有工作。 How do I move all my changes in feature-branch
so that they sit in a new branch but one that is branched off release
branch?如何移动我在
feature-branch
中的所有更改,以便它们位于一个新分支中,但另一个分支是从release
分支分支出来的?
What have I tried?我尝试了什么?
I tried using rebase --onto
but I got the following error:我尝试使用
rebase --onto
但出现以下错误:
$ git rebase --onto release-branch feature/1 feature/1a
$ git rebase --onto 发布分支功能/1 功能/1a
fatal: fatal: no such branch/commit 'feature/1a'
致命:致命:没有这样的分支/提交'feature/1a'
To duplicate the commits from feature
, and only them (no commit from develop
before or after feature
forked from it), you can use the following commands:要复制来自
feature
的提交,并且只复制它们(在从它派生的feature
之前或之后没有来自develop
的提交),您可以使用以下命令:
git checkout -B feature release # Checkout `release` and bring `feature` along
git cherry-pick develop..feature@{1} # Retrieve commits from `feature` which are not on `develop`
Try this commands (pseudo-code: apply your naming correctly)试试这个命令(伪代码:正确应用你的命名)
git checkout release
git rebase feature
After these commands, you will have work from feature
branch in release
branch.在这些命令之后,您将在
release
分支的feature
分支中进行工作。
However if develop
has accepted commits after feature
branch was checked out, those commits will not be present nor in feature
nor in release
.但是,如果在检出
feature
分支后develop
已接受提交,则这些提交将不存在,也不存在于feature
或release
中。
You will need to rebase your release
branch agains master in order to have them in release
branch.您需要将
release
分支重新设置为 master 以便将它们放在release
分支中。 By running:通过运行:
git checkout release
git rebase develop
PS Here is the link that describes the rebase
command https://git-scm.com/docs/git-rebase PS这里是描述
rebase
命令https的链接://git-scm.com/docs/git-rebase
I think the best way to do this is to rebase your Feature branch onto Release.我认为最好的方法是将您的功能分支重新定位到发布。 The git rebase command is quite flexible.
git rebase 命令非常灵活。 You can tell it where to move your branch, and how much of your branch to move.
您可以告诉它要将分支移动到哪里,以及要移动多少分支。
This command will move the Feature branch to branch off Release, starting from the commit after the Develop branch:此命令会将 Feature 分支移至 Release 分支,从 Develop 分支之后的提交开始:
git rebase --onto Release Develop Feature
or alternatively:或者:
git checkout Feature
git rebase --onto Release Develop
No need to create a new branch or delete your original one.无需创建新分支或删除原始分支。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.