modify files

This commit is contained in:
2025-07-16 09:09:21 +08:00
parent 5fe5d34888
commit 197dcbfc03
5 changed files with 68 additions and 1 deletions

46
commit.sh Executable file
View File

@ -0,0 +1,46 @@
#!/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 files"
#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 "✅ 代码提交成功!"