在git中拆分合并 [英] splitting a merge in git

查看:153
本文介绍了在git中拆分合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对git很陌生.我想知道-在git中是否可以多次合并来自不同分支的两个文件? 例如说我在master分支中有file.txt,在test分支中有相同文件的另一个版本.现在,我想将测试分支文件中的两个特定片段合并到主要片段中;但我想按顺序执行此操作,以便可以验证每次更改的效果.

I am very new to git. I wonder -- is it possible in git to merge two files (from different branches) multiple times? e.g. say I have file.txt in the master branch, and another version of the same file in the test branch. Now, there are two particular fragments in the test branch file that I would like to merge into the main one; but I'd like to do it sequentially, so that I could verify the effects of each change.

所以我做git merge test --no-ff,这会产生冲突.我编辑文件以合并测试分支中的第一个片段,并将第二个片段保留在master分支中,然后测试是否一切正常.

So I do git merge test --no-ff, this produces conflicts. I edit the file to merge the first fragment from the test branch and keep the second one as it was on the master branch, and test if everything is OK.

在那之后,我想对我之前忽略的第二个片段再次做同样的事情;但是git merge拒绝执行任何操作,因为它说事情是最新的,因为测试中的文件已经被合并一次.

After that, I would like to do the same thing again with the 2nd fragment that I have previously ignored; however git merge refuses to do anything as it says things are up to date, because the file in test has already been merged once.

有没有办法强迫git进行这样的重复合并?我认为可以使用git show在测试分支中生成文件的临时副本,然后进行复制粘贴,但这看起来很丑.

Is there a way to force git to conduct such a repeated merge? I figured that I can use git show to produce a temporary copy of the file in the test branch and then copy-paste, but this seems ugly.

推荐答案

您需要将对文件的更改拆分为多个提交.现在,一次合并每个提交.

You would need to split the changes to the file into multiple commits. Now merge each commit one at a time.

这篇关于在git中拆分合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆