我们如何在git的两个分支之间同步文件? [英] How can we sync files between two branches in git?

查看:551
本文介绍了我们如何在git的两个分支之间同步文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我分叉了一个有很多分支的项目.我特别喜欢两个分支.

I have forked a project with many branches. Two branches in particular interest me.

1.8.x
2.2.x

我引入了一个新文件"newfile.source",并将其更改为两个分支中都存在的文件"existingfile.source".我想在两个分支之间同步在newfile和existingfile中所做的更改.

I have introduced a new file, 'newfile.source' and changes to a file 'existingfile.source' that exists in both branches. I want to synchronize the changes I make in newfile and existingfile between both branches.

我在脑海中建模的方式是这样的:

The way I model this in my head is something like this:

commit -- commit -- commit -- commit -- commit -- commit -- commit -- 2.2.x
                            \
                             -- commit -- 1.8.x

我想拥有一个结构(分支,但仅包含对现有文件和新文件的更改),我可以对其进行更改并合并到1.8.x和2.2.x中:

I want to have a structure (branch but only consisting of the changes to existingfile and newfile) that I can make changes to and merge into 1.8.x and 2.2.x:

nothing -- custom_changes -- nothing

,然后执行类似的操作:

and then do something like:

git checkout 2.2.x
git merge custom_changes
git checkout 1.8.x
git merge custom_changes

推荐答案

只需将其提交到一个分支(像往常一样).我希望在这里使用较新的版本(2.2.x).然后切换到旧分支(1.8.x)并使用 cherry-pick

Just commit it to one branch (like usual). I would prefer the newer one (2.2.x) here. Then switch to the old branch (1.8.x) and "backport" the commit using cherry-pick

这篇关于我们如何在git的两个分支之间同步文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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