如何在多个分支上为相同的更改创建多个Pull请求



假设我们有三个不同的分支:

  1. Main Branch -在这里开发人员为新特性推送新的代码更改
  2. 发布分支-这是生产分支
  3. Demo Branch—该分支用于向客户演示新特性。

所以现在的问题是,每当我需要为发布分支上的升级提供热修复时,我必须为相同的更改手动创建三个不同的PR,分别为Main, release和Demo分支,这是一个相当手动的任务,有点令人沮丧。

目前,我将更改提交到发布分支,并挑选提交到其他分支,并为所有这三个分支创建单独的pr。

是否有办法一次为多个分支的相同更改创建多个pr ?

谢谢你的帮助或任何建议谢谢!

没有这样的功能。

拉请求是从一个分支到另一个分支(pr不是用于提交)如果在main和/或demo上"重复",从hotfix1分支(基于release分支)到release的pr将在大多数情况下产生不希望的结果。在多个分支中"重复"一个PR与优先选择一个热修复提交不同(优先选择PR从目标分支创建一个"临时"分支)。


这是怎么回事

假设该特性仅为简单起见而适用于单个提交pr。从hotfix1toreleasethere would be an option to select extra target branches for an automatically created cherry-pick tomain,demo’等创建PR时。我想这是可能的,但GitHub目前没有。

您可以使用Github CLI和bash脚本创建多个分支的pr。例如:

for branch in main release
do
gh pr create -B $branch -t "My PR title" -b "My PR description"
done

感谢@D Malan的建议,我创建了下面的shell脚本。希望它也能帮助到其他人。

#!/bin/sh
declare ISSUE_ID COMMIT_MESSAGE PR_TITLE PR_DESSCRIPTION PR_MODE;
receive_user_input() {
echo "These are the List of Modified Files I could find:-";
git ls-files -m;

read -p "Provide a valid ID for this fix: " ISSUE_ID;
read -p "Name the other remote branches (space separated) you want to create PR for: " REMOTE_BRANCHES;

read -p "Provide a proper commit message: " COMMIT_MESSAGE;

read -p "Provide a title for your PR: " PR_TITLE;

read -p "Provide a description for your PR: " PR_DESSCRIPTION;
read -p "Do you want to create PR in draft Mode (Y/N)? : " PR_MODE;

};
create_pull_request() {
# use to exit when the command exits with a non-zero status.
set -e;

# Commit changes to the hotfix branch and create a PR.
{
git checkout -b hotfix/$ISSUE_ID;
git add $(git ls-files -m);
git commit -m "$COMMIT_MESSAGE";
COMMIT_ID=$(git rev-parse HEAD);
git push --set-upstream origin hotfix/$ISSUE_ID;
gh pr create --base release --head hotfix/$ISSUE_ID --title "$PR_TITLE" --body "$PR_DESSCRIPTION" --assignee "@me" --draft; 

# Loop over the other remote branches and cherry-pick the commit and create PR.
for branch in $REMOTE_BRANCHES ; do
git fetch origin;
git checkout $branch;
git pull origin $branch;
git checkout -b fix/$branch/$ISSUE_ID;
git cherry-pick $COMMIT_ID;
git push origin fix/$branch/$ISSUE_ID;
gh pr create --base "$branch" --head "fix/$branch/$ISSUE_ID" --title "$PR_TITLE" --body "$PR_DESSCRIPTION" --assignee "@me" --draft; 
done
} > logs.txt 2>&1;
# 1.command > logs.txt: redirects the output of command(stdout) to logs.txt file.
# 2.2>&1: redirects stderr to stdout, so errors (if any) also go to the logs.txt file.
};
receive_user_input;
create_pull_request;

最新更新