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

问题描述 投票:0回答:3

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

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

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

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

有没有什么办法一次性为多个分支的同一个变更创建多个PR?

感谢您的帮助或任何建议 谢谢!

git github gitlab bitbucket pull-request
3个回答
1
投票

没有这样的功能

拉取请求是从一个分支到另一个分支(pr 不是提交)并且 从

hotfix1
分支(基于
release
分支)到
release
的 pr 如果“重复”到
main
和/或
demo
在大多数情况下将产生不良结果。 在多个分支中“重复”一个 PR 与挑选修补程序提交不同(挑选 PR 从目标分支创建一个“临时”分支)。


这怎么行

为了简单起见,假设该功能仅适用于单个提交的 PR。当从 hotfix1

to
release
there would be an option to select extra target branches for an automatically created cherry-pick to
main
, 
demo` 等创建 PR 时。我想这是可能的,但 GitHub 目前没有它。


1
投票

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

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

0
投票

感谢@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;
© www.soinside.com 2019 - 2024. All rights reserved.