[英]How to copy a commit from one branch to another in git without any merging?
I have 2 branches a master and an experimental. 我有两个分支,一个主人和一个实验。 A shown:
显示:
master-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-Y
\
-x-x-x-x
My experimental is quite outdated and i was hoping to update it by simply copying the last commit in the master branch ( Y ) to experimental: 我的实验已经过时了,我希望通过简单地将主分支( Y )中的最后一次提交复制到实验来更新它:
master-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-x-Y
\
-x-x-x-x-Y
If possible, I don't want to have to do any merging I want to overwrite anything in the experimental (master is my main priority). 如果可能的话,我不想做任何合并我想要在实验中覆盖任何东西(master是我的主要优先级)。
Edit: Let me briefly explain the situation: When i try to merge commits at the tips of the master and experimental branch, I get a lot of merge conflicts! 编辑:让我简要解释一下这种情况:当我尝试在主和实验分支的提示下合并提交时,我会遇到很多合并冲突! The same happens if i try to cherry-pick from the experimental onto the master!
如果我尝试从实验中挑选到主人那里,也会发生同样的事情! I was hoping to avoid them as i simply don't want any of the changes on the experimental!
我希望避免它们,因为我根本不想要实验中的任何变化! Up until now, I have been cherry-picking from master to experimental and when there are merge conflicts, I just keep changes of master branch.
到目前为止,我一直在挑选从大师到实验,当有合并冲突时,我只是保持主分支的变化。 But after doing it many times, i was hoping that there may be some way in which i can do something like a merge except where (i am not prompted with any merge conflicts as master changes is all i need (for all I know it wouldn't matter what was previously on the experimental branch!
但经过多次这样做之后,我希望可能有某种方式我可以做一些像合并之类的东西,除非在哪里(我没有提示任何合并冲突因为主变化是我所需要的所有(因为我知道它不会不管以前在实验分支上做了什么!
To cherry-pick just commit Y
from master
onto experimental
: 樱桃挑选 只是将
master
Y
提交到experimental
:
git checkout experimental
git cherry-pick Y
Alternatively: 或者:
git checkout experimental
git cherry-pick master
...Will apply the change introduced by the commit at the tip of the master
branch and create a new commit in experimental
with this change. ...将在
master
分支的顶端应用提交引入的更改,并在此experimental
使用此更改创建新提交。
Here is what I initially tried!: 这是我最初的尝试!:
git checkout experimental
git rebase --onto <COMMIT ID OF LAST MASTER COMMIT> experimental
On trying this code, I found that not only the commit at the tip of the master but also the entire experimental branch became a clone of the master! 在尝试这段代码时,我发现不仅在主人的尖端提交而且整个实验分支都成为了主人的克隆! Yes, it is not an elegant solution and a bad usage of git!
是的,它不是一个优雅的解决方案和一个糟糕的使用git!
However, as pointed out by @Johnsyweb, the optimum solution would be to do a merge of experimental and master but, 但是,正如@Johnsyweb所指出的,最佳解决方案是将实验和主人合并, 但是,
with Git preferring to take the changes on master over the changes on experimental
与Git相比,他更愿意对主人的变化进行实验性的改变
Hence doing a: 因此做一个:
git checkout experimental
git merge -Xtheirs master
should work fine. 应该工作正常。 Although it says merge, since it only considers the changes of the experimental branch over the master one, it is more like a copy from experimental to master for all practical purposes.
虽然它说合并,因为它只考虑实验分支相对于主分支的变化,它更像是从实验到硕士的副本,用于所有实际目的。
(See a similar discussion here ) (见这里类似的讨论)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.