[英]git - rebase branch, built on top of another, on master
I am working on a feature in a repo. 我正在处理回购中的功能。 I have created a feature branch (say branch_1
) and another branch (say branch_2
) on top of branch_1
. 我创建了一个特性分支(比如branch_1
)和另一个分支(比如branch_2
之上) branch_1
。 I used to rebase branch_2
every time branch_1
was updated, but now the branch_1
is being merged into master
so I want to rebase branch_2
into master
, so that branch_2
have only its own changes. 我曾经在每次更新branch_2
时对branch_1
进行重新设置,但是现在将branch_1
合并到master
因此我想将branch_2
为master
,以便branch_2
仅具有自己的更改。 How do I do this? 我该怎么做呢? Also is the right way or is there any other method? 还是正确的方法还是还有其他方法?
You can just rebase this branch on master: 您可以将此分支基于master:
src/myproject (branch2)$ git rebase master
Any changes in contains that are already in master will be "swallowed" into those master changes, and you'll remain with just the distinct changes this branch contains. master中包含的任何更改都将被“吞噬”到这些master更改中,并且您将只剩下该分支包含的独特更改。
It's quite convenient to never rebase your feature branches but merge them with the upstream. 永远不要重新构建功能分支,而是将其与上游合并是非常方便的。 However, it kind of assumes that you don't deliver your merges but only the squashed content of the branches (because who wants all those merges on master, right?). 但是,这种假设是您不交付合并而仅交付分支的压缩内容(因为谁希望所有这些合并都在主服务器上进行,对吧?)。
In large systems it can be quite nice to have this uplift history preserved in your development branch, since the uplift can introduce new problems to your feature. 在大型系统中,最好将这种升级历史记录保留在您的开发分支中,因为升级会给您的功能带来新的问题。 Rebasing the feature branch can hide what introduced the problem, even though the problem is of course the same. 重新设置功能分支可以隐藏导致问题的原因,即使问题当然是相同的。
Say you have branches master
, feat1
off of master
and feat2
off of feat1
. 假设您有分支master
, feat1
脱离master
, feat2
脱离feat1
。
To uplift feat2
to a new feat1
you do: 要将feat2
提升到新feat1
请执行以下操作:
git fetch
git checkout origin/feat2
git merge origin/feat1
git push origin feat2
Uplifting feat1
to a new master
would be: 将feat1
提升为新master
将是:
git fetch
git checkout origin/feat1
git merge origin/master
git push origin feat1
But then say you want to switch upstream for feat2
because feat1
has been delivered to master
. 但是然后说,由于feat1
已交付给master
因此您想切换到feat2
上游。 No problem. 没问题。
git fetch
git checkout origin/feat2
git merge origin/master
git push origin feat2
There are several possible solutions for you request. 有几种可能的解决方案供您请求。 If you are not satisfied with Mureinik's answer you can try to rebuild your branch using git cherry-pick
. 如果您对Mureinik的回答不满意,可以尝试使用git cherry-pick
重建分支。 Basically, create a new branch from master
and pick all commits from the place where branch_1
was merged into master
to HEAD
commit of branch_2
. 基本上,创建一个新的分支master
,并挑选从住的地方都提交branch_1
被合并到master
到HEAD
提交的branch_2
。 To do so you will have to use a command like (assuming you are on the new branch): 为此,您将必须使用类似以下的命令(假设您位于新分支上):
git cherry-pick branch_2~10 branch_2
assuming that 10 is the number of commits in branch_2
after merging of branch_1
. 假设合并branch_2
后, branch_1
的提交数为10。 branch_2
without specifying a number of 'commits back' is the latest commit of the branch. branch_2
未指定“ commit back”的数量是分支的最新提交。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.