今は開発環境でM1 macを使っているのだけれど、色々あってプルリクを送りたいブランチと自分の手元のブランチが異なっているケースがある。ようはM1専用のcommitを積んでいるが、これをプルリクに含めたくないケース。
最近はgit慣れてないのもあって、commitする度にcheckoutしてcherry-pickしていたのだけど、めんどうなのでスクリプトを書いた。
自分が今作業しているブランチをhoge_m1
という命名規則にして、プルリクを出すブランチをhoge
にするみたいな運用。suffixで分類する。
#!/usr/bin/env perl use strict; use warnings; my $git_branches = `git branch`; die "$git_branches\n" if ($git_branches =~ /fatal: not/); my $current_git_branch = `git branch --show-current`; chomp $current_git_branch; my $target_branch; if ($current_git_branch =~ /(.*)_m1$/) { $target_branch = $1; die "not found $target_branch branch" unless ($git_branches =~ /$target_branch/); } system("git","commit"); system("git", "checkout", $target_branch); system("git", "cherry-pick", $current_git_branch); system("git", "checkout", $target_branch);
オチ
git rebase
勉強した方が早かった気がする