git部分合并,不是整个分支 [英] git partial merge, not whole branch

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

问题描述

我已经阅读了关于合并 Git:合并公共和私人分支,同时保持两个分支中的某些文件完好无损和其他人,并没有找到解决方案。



在我的我感觉需要做相反的合并策略。在并行开发中,我必须在任意分支上保留一些相同的文件。从另一方面来说,我不想做压缩或不承诺合并,但差异很大,可能会打破目前的测试分支状态。



我想要的东西就像

git checkout testing



git merge config.xml -b development git merge config \ * .xml -b development



我想这就像 git merge-files ... 命令,但第二个文件从分支传递,而不是从文件系统传递。
是否有可能?或者可能有一种解决方法?子模块?属性?



谢谢

解决方案

做到。



一,你可以挑选你想要的更改,它只应用一次提交。例如,如果有一个更改只涉及 config.xml ,您可以用 $ b $ git cherry-pick $ COMMIT_ID_YOU_WANT

你也可以抓住<

  $ git checkout testing $ b code> config.xml  $ b $ git checkout development  -  config.xml 

这会为您带来相同版本的 config.xml 存在于开发分支中,但请注意它不会引入文件更改的历史记录。


I've read about some tricks with merge in Git: merging public and private branches while while keeping certain files intact in both branches and others and not found a solution.

In my case I'm feeling need to do opposite merge strategy. In parallel development I have to keep some files same across the arbitrary branches. From other side I do not want to do squash or no-commit merge, while difference are significant and could break current state of testing branch.

What I want something like

git checkout testing

git merge config.xml -b development or git merge config\*.xml -b development

I guess this is like git merge-files ... command, but second file delivered from the branch, not from the filesystem. Is it possible? or may be there is a kind of workaround? submodules? attributes?

Thanks

解决方案

There are a couple things you can do.

One, you can cherry-pick the changes you want, which applies only a single commit. For example, if there's a change that only touches config.xml, you can cherry-pick it with

$ git cherry-pick $COMMIT_ID_YOU_WANT

You could also just grab config.xml from the development branch:

$ git checkout testing
$ git checkout development -- config.xml

That'll get you the same version of config.xml that exists in the development branch, but note that it won't pull in the history of changes to the file.

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

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