同步两个仅通过几个文件不同的GIT分支 [英] Syncing two GIT branches that only differ by a couple of files

查看:194
本文介绍了同步两个仅通过几个文件不同的GIT分支的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为当前项目定义了几个分支,除了主分支之外,所有主分支都仅由相同的一小组文件(少于十个)与主分支不同。

在master中实现一个新功能后,我想用最少的努力将这些更改和附加内容复制到其他分支。这里推荐的方法是什么?

解决方案

您有三种选择:


  • merge :如果master的所有更改都需要在一个分支中可见,那么很有趣。但并非总是如此。

  • cherry-pick :仅将某个提交应用于分支


  • rebase :最好的解决方案如果你的分支尚未被推送:你重放你的分支在主控制器上的提交




但是:在这三种情况下,您需要签出要整合更改的分支,并对每个分行重复该操作。



除非你的分行是由一个到另一个:

  --- o分行B1 
\
- ---○分支B2
\
----分支B3

在这种情况下,您可以:仅限
$ b


  • 将更改合并到最具体的分支 ),因为在这个FAQ中推荐

  • 在B3上完成你的工作

  • 然后在父分支B2上合并(如果在B2上没有发生进化,这实际上是一个快进合并)
  • 重复B1(即:完成B2上的工作, git checkout B1 git merge B2


I have a couple of branches defined for the current project where all but the master branch differ from master only by the same small set of files (less than ten).

After implementing a new feature in master I would like to replicate those changes and additions to the other branches with the least effort. What's the recommended approach here?

解决方案

You have three choices:

  • merge: interesting if all changes of master need to be visible in one branch, but that is not always the case

  • cherry-pick: to only apply certain commit to a branch

  • rebase: the best solution if your branch has not yet been pushed: you replay the commit of your branch on top of master

But: in the three cases, you need to checkout the branch where you want to integrate the changes, and repeat that for each branches.

Unless your branches are made from one to another:

---o             branch B1
    \
     ----o       branch B2
          \
           ----o branch B3

In that case, you could:

  • only merge the changes to the most specific branch (B3 here), as recommanded in this FAQ
  • finish your work on B3
  • then merge on the parent branch B2 (if no evolutions took place on B2, this is actually a fast-forward merge)
  • repeat for B1 (that is: finish your work on B2, git checkout B1, git merge B2)

这篇关于同步两个仅通过几个文件不同的GIT分支的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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