Files
stock/commit.sh
2025-04-13 16:51:58 +08:00

46 lines
996 B
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# 确保脚本有执行权限(只需执行一次)
# chmod +x git_commit.sh
# 检查是否在 Git 仓库内
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "❌ 当前目录不是 Git 仓库,请先执行 git init"
exit 1
fi
# 获取 commit message
commit_msg="$1"
# 如果没有提供 commit message提示用户输入
if [ -z "$commit_msg" ]; then
commit_msg="modify scripts"
#read -p "请输入 commit message: " commit_msg
#if [ -z "$commit_msg" ]; then
# echo "❌ 提交信息不能为空!"
# exit 1
#fi
fi
# 添加所有更改
git add .
if [ $? -ne 0 ]; then
echo "❌ git add 失败!"
exit 1
fi
# 提交更改
git commit -m "$commit_msg"
if [ $? -ne 0 ]; then
echo "❌ git commit 失败!"
exit 1
fi
# 推送到远程仓库
git push -u origin master
if [ $? -ne 0 ]; then
echo "❌ git push 失败!请检查远程仓库设置。"
exit 1
fi
echo "✅ 代码提交成功!"