我怎样才能从上游分支合并 "cascading" 并使用一个命令将合并传递给所有下游分支?

How can I so a "cascading" merge from an upstream branch and pass the merge to all downstream branches with one command?

我有一个“父”分支。分支 A 是父分支,分支 B 是分支 A 的分支,分支 C 是分支 B 的分支:

------ Parent
  \----Branch A
     \------ Branch B
        \------- Branch C

我想将一些更改合并到分支 A,然后将这些相同的更改传递到分支 B 和 C。有什么方法可以轻松完成吗?也许我可以使用列出包含的分支的 --contains 机制并使用 bash 来做到这一点?我用谷歌搜索了类似的解决方案,但没有找到。

我通常的做法是将 A 变基到其父级,然后将 B 变基到 A,再将 C 变基到 B。

很遗憾,Git 不会为您执行此操作。您可以递归地使用 git branch --contains 编写脚本。

好的,我已经用 perl 编写的 git hub 中的粗略 post-commit 钩子完成了它。我的分支命名约定允许我根据分支名称执行此操作。从 branch --list 获取输出需要一些小技巧,即在 git.

中关闭和重新打开分页设置
#!/usr/bin/env perl

use strict;
use warnings;

# get the current branch name
my $curr_branch = `git branch --show`;
chomp $curr_branch;

# get the names of all the branches that have this branch as parent and merge commit into each of them
if ($curr_branch eq 'configs') {
    `git config --global pager.branch false`;
    my $out = `git branch --list --no-color --no-column`;
    `git config --global pager.branch true`;
    my @list = grep { /\scfg_/ } split /\n/, $out;
    foreach my $l ( @list ) {
        print "Merging to $l\n";
        `git checkout $l`;
        `git merge --no-edit configs`;
    }
}

`git checkout configs`;

我已将我未使用的 post-merge 脚本符号链接到此 post-commit 脚本,因此它也会在与另一个分支合并时触发。