我有一個“父”分支。分支 A 是 Parent 的分支,分支 B 是分支 A 的分支,分支 C 是分支 B 的分支:
------ Parent
\----Branch A
\------ Branch B
\------- Branch C
我想將一些更改合并到分支 A,然后將這些相同的更改傳遞到分支 B 和 C。有沒有一種方法可以輕松完成?也許我可以使用--contains列出包含分支的機制并使用 bash 執行此操作?我用谷歌搜索了這樣的解決方案,但沒有找到。
uj5u.com熱心網友回復:
我通常的方法是將 A 重新定位到其父級,然后將 B 重新定位到 A,然后將 C 重新定位到 B。
不幸的是,Git 不會為你做這件事。git branch --contains您可以使用遞回撰寫腳本。
uj5u.com熱心網友回復:
好的,我已經在 git hub 中用 perl 撰寫了一個粗略的 post-commit 鉤子。我的分支命名約定允許我根據分支名稱執行此操作。需要一些小技巧來獲取 git 的輸出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腳本,因此它也會在與另一個分支合并時觸發。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/435157.html
