[英]How can I merge a file history from a branch to another in git?
So first check the following image, I tried to represent what I need 因此,首先检查下图,我试图代表我的需求
The green squares are the commits, and the yellow, brown and red are parts of those commits (in my case commits to specifically 3 files spread through the commits). 绿色方块是提交,黄色,棕色和红色是这些提交的一部分(在我的情况下,具体来说是提交中分布的3个文件)。
There are no further changes made on dev 对开发人员没有进一步的更改
What actually happened: I was working on a branch and found out that some changes were actually useful on the dev
branch and were not actually related to the dev2
branch. 实际发生的情况:我在一个分支上工作,发现一些更改实际上对
dev
分支有用,而实际上与dev2
分支dev2
。 So I wanted that those changes on the dev
branch. 所以我希望在
dev
分支上进行这些更改。
git checkout
git merge
I actually want the modifications to get out of the dev2
branch and go into the dev
branch, so if I do the checkout>commit the modifications will be on both branches, that's why I wouldn't like to do it. 我实际上希望修改脱离
dev2
分支并进入dev
分支,所以如果我执行checkout> commit,则修改将在两个分支上进行,这就是为什么我不愿意这样做。
Is this even possible? 这有可能吗? How can I do it?
我该怎么做?
You can just find the sha
of the last commit that should be in dev (the red square) by using git log
, and then go to your master branch checkout master
and just say git merge SHA
where SHA of the red square. 您可以使用
git log
来找到应该在dev(红色方块)中的最后一次提交的sha
,然后转到master分支checkout master
然后说git merge SHA
,其中红色方块的SHA。 This is quite a common thing in git. 这在git中很常见。 It happens a lot with forked repos, to merge in the updates of the original.
分叉的回购经常发生,合并到原始版本的更新中。
Remember though that this gets the whole commits, i am not sure if that is what you want. 请记住,尽管这可以获取全部提交,但是我不确定这是否是您想要的。 If you want just some files from those commits, it will be a lot harder.
如果您只想从这些提交中获取一些文件,则要困难得多。 Then you should have a look at this question .
那你应该看看这个问题 。
Yes, this is possible. 是的,这是可能的。 You need to do three things:
您需要做三件事:
git checkout dev
git checkout dev
git cherry-pick yellow
, git cherry-pick brown
, git cherry-pick red
git cherry-pick yellow
, git cherry-pick brown
, git cherry-pick red
dev2
onto dev
: git checkout dev2
, git rebase --onto dev
dev2
dev
: git checkout dev2
, git rebase --onto dev
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.