git 脚本快速提测功能
1. 调用示例
git sfm 功能更新
2. 创建命令方法
git config --global alias.sfm '!f() {
if [ $# -eq 0 ]; then
echo "========================================================";
echo "❌ 错误:请输入提交信息!";
echo "💡 用法:git sfm \"新功能提测\"";
echo "========================================================";
exit 1;
fi;
commit_msg="$*";
current_branch=$(git symbolic-ref --short HEAD);
echo "========================================================";
echo "🏠 当前工作分支:$current_branch";
if [ "$current_branch" = "test" ]; then
echo "========================================================";
echo "❌ 禁止在 test 分支执行提交操作!";
echo "========================================================";
exit 1;
fi;
echo "========================================================";
echo "📥 步骤1:正在暂存所有更改...";
echo "👉 执行命令:git add .";
git add . || { echo "❌ git add 执行失败"; exit 1; };
echo "========================================================";
echo "📝 步骤2:生成提交记录:\"$commit_msg\"";
echo "👉 执行命令:git commit -m \"$commit_msg\"";
git commit -m "$commit_msg" || { echo "❌ git commit 提交失败"; exit 1; };
echo "========================================================";
echo "📤 步骤3:推送本地分支到远程(不存在自动创建)";
echo "👉 执行命令:git push origin -u \"$current_branch\"";
git push origin -u "$current_branch" || { echo "❌ 推送分支失败"; exit 1; };
echo "========================================================";
echo "🔀 步骤4:切换到 test 分支";
echo "👉 执行命令:git checkout test";
git checkout test || { echo "❌ 切换 test 分支失败"; exit 1; };
echo "========================================================";
echo "⬇️ 步骤5:拉取 test 最新代码...";
echo "👉 执行命令:git pull origin test";
git pull origin test || { echo "❌ 拉取 test 失败,请处理本地修改"; exit 1; };
echo "========================================================";
echo "🔀 步骤6:合并 $current_branch 到 test 分支...";
echo "👉 执行命令:git merge --no-edit \"$current_branch\"";
git merge --no-edit "$current_branch" || { echo "❌ 合并失败!请解决冲突后重试"; exit 1; };
echo "========================================================";
echo "📤 步骤7:推送 test 分支到远程仓库...";
echo "👉 执行命令:git push origin test";
git push origin test || { echo "❌ 推送 test 失败"; exit 1; };
echo "========================================================";
echo "✅ 步骤8:合并提测流程全部完成!";
echo "🔙 步骤9:自动切回原开发分支:$current_branch";
echo "👉 执行命令:git checkout \"$current_branch\"";
git checkout "$current_branch" || {
echo "⚠️ 切回原分支失败,但提交+提测已完成!";
exit 1;
};
echo "========================================================";
echo "🎉 恭喜:全部操作 100% 完成!";
echo "📌 结果:代码已提交 + 已推送 + 已提测";
echo "========================================================";
}; f'
本作品采用《CC 协议》,转载必须注明作者和本文链接
关于 LearnKu