Bootstrap

git自动合并代码脚本

#!/bin/bash

# 函数:处理合并并解决冲突
merge_branch() {
    target_branch="$1"
    source_branch="$2"
    commit_message="$3"

    # 切换到目标分支并拉取最新代码
    echo ">>>>>>>>>>>>>>>>>>>> 切换到 $target_branch 分支并拉取最新代码..."
    git checkout "$target_branch"
    git pull origin "$target_branch"

    # 合并代码并使用预定义的提交信息
    echo ">>>>>>>>>>>>>>>>>>>> 合并 $source_branch$target_branch..."
    git merge "$source_branch" -m "$commit_message"

    # 检查是否发生合并冲突
    if [ $? -ne 0 ]; then
        echo ">>>>>>>>>>>>>>>>>>>> 合并 $source_branch$target_branch 时遇到冲突。请解决冲突并继续..."
        echo ">>>>>>>>>>>>>>>>>>>> 请手动解决冲突后,继续执行脚本"
        exit 1
    fi

    # 推送合并后的代码到远程仓库
    echo ">>>>>>>>>>>>>>>>>>>> 推送合并后的代码到远程仓库..."
    git push origin "$target_branch"
}

# 切换到 2024_05_ft 分支
echo ">>>>>>>>>>>>>>>>>>>> 切换到 2024_05_ft 分支..."
git checkout 2024_05_ft
git pull origin 2024_05_ft

# 合并到 2024_05_main 分支
merge_branch "2024_05_main" "2024_05_ft" "Merge branch '2024_05_ft' into 2024_05_main"

# 合并到 saas_dev 分支
merge_branch "saas_dev" "2024_05_main" "Merge branch '2024_05_main' into saas_dev"

# 合并到 pvt_dev 分支
merge_branch "pvt_dev" "2024_05_main" "Merge branch '2024_05_main' into pvt_dev"

# 判断是否执行 合并到 xc_dev 的操作
if [ "$1" = "--xc" ]; then
    echo ">>>>>>>>>>>>>>>>>>>> 合并 pvt_dev 到 xc_dev 分支..."
    merge_branch "xc_dev" "pvt_dev" "Merge branch 'pvt_dev' into xc_dev"
fi

# 回到原始分支
echo ">>>>>>>>>>>>>>>>>>>> 回到原始分支..."
git checkout 2024_05_ft

在这里插入图片描述

;