英文:
Apply only the changes from a new branch onto an older branch
问题
I have 2 branches : feature1
and feature2
which are based on the develop
branch. feature1
is based on an older commit while feature2
is more recent.
我有两个分支:feature1
和 feature2
,它们都基于 develop
分支。feature1
基于一个较旧的提交,而 feature2
更加最近。
I want to get only the commits from feature2
that are not in develop onto feature1
.
我想要将仅来自 feature2
的那些不在 develop
分支上的提交应用到 feature1
分支上。
I tried git rebase --onto feature1 develop feature2
as suggested in this answer, but I see that commits from develop are still getting applied onto feature1
. What am I missing here?
我尝试了 git rebase --onto feature1 develop feature2
,如此 答案 中建议的,但我发现来自 develop
的提交仍然被应用到 feature1
上。我在这里漏掉了什么?
Update : It turns out that the local develop
branch was not up-to-date with the remote develop
while feature2
was based on a more recent commit on the remote develop
. This is why the commits from the remote develop
were getting rebased.
更新:原来本地的 develop
分支与远程的 develop
分支不同步,而 feature2
是基于远程 develop
分支上的一个更近的提交。这就是为什么来自远程 develop
的提交被重新基于的原因。
英文:
I have 2 branches : feature1
and feature2
which are based on the develop
branch. feature1
is based on an older commit while feature2
is more recent.
I want to get only the commits from feature2
that are not in develop onto feature1
.
I tried git rebase --onto feature1 develop feature2
as suggested in this answer, but I see that commits from develop are still getting applied onto feature1
. What am I missing here?
Update : It turns out that the local develop
branch was not up-to-date with the remote develop
while feature2
was based on a more recent commit on the remote develop
. This is why the commits from the remote develop
were getting rebased.
答案1
得分: 1
正如knittl在评论中提到的,git rebase --onto A B C
总是采用提交范围B..C
(即^B C
)。
这意味着它应该以来自D
(不包括)到f2
HEAD的提交为目标(这些提交不应该来自develop
,可从develop
访问):
f2--f2(feature2)
/
--d--d--D--d(develop)
\
f1--f1(feature1)
git rebase --onto feature1 develop feature2
--d--d--D--d(develop)
\
f1--f1(feature1)
\
f2'--f2'(feature2)
> feature1
早些时候已合并到feature2
,而没有删除feature1
分支。
因此:
f1--f1--f1--f1 (feature1)
/ \
/ f2--f2--f2 (feature2)
/ /
--d--d--d--d--d (develop)
然而,OP补充道:
>我的本地develop
分支与远程develop
不同步,而其他分支都是最新的。
这就是为什么来自远程develop
的提交正在被重新基于的原因。
所以:
git fetch
git switch feature1
git rebase --onto feature1 origin/develop feature2
英文:
As knittl mentions in the comments, git rebase --onto A B C
always takes the commit range B..C
(i.e. ^B C
)
That means it should target commits from D
(excluded) up to f2
HEAD (none of those commits should be from develop
, reachable from develop
):
f2--f2 (feature2)
/
--d--d--D--d (develop)
\
f1--f1 (feature1)
git rebase --onto feature1 develop feature2
--d--d--D--d (develop)
\
f1--f1 (feature1)
\
f2'--f2' (feature2)
> feature1
was merged into feature2
earlier without deleting the feature1
branch.
So:
f1--f1--f1--f1 (feature1)
/ \
/ f2--f2--f2 (feature2)
/ /
--d--d--d--d--d (develop)
However, the OP adds:
> My local develop
branch was not up-to-date with the remote develop while the other branches were up-to-date.
This is why the commits from the remote develop were getting rebased
So:
gi fetch
git switch feature1
git rebase --onto feature1 origin/develop feature2
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论