Ingen beskrivning
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

gct.sh 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. # 脚本用法:./git-commit-and-tag.sh "你的提交描述" "版本号"
  3. # 检查参数数量
  4. if [ $# -ne 2 ]; then
  5. echo "错误: 脚本需要2个参数。"
  6. echo "用法: $0 \"提交描述\" \"版本号\""
  7. echo "示例: $0 \"修复了登录问题\" \"v1.2.3\""
  8. exit 1
  9. fi
  10. # 分配参数
  11. COMMIT_MESSAGE="$1"
  12. VERSION_TAG="$2"
  13. # 检查当前目录是否为Git仓库
  14. if ! git rev-parse --git-dir > /dev/null 2>&1; then
  15. echo "错误: 当前目录不是一个Git仓库。"
  16. exit 1
  17. fi
  18. # 检查是否有未暂存的更改
  19. if [ -z "$(git status --porcelain)" ]; then
  20. echo "提示: 没有检测到任何更改需要提交。"
  21. exit 0
  22. fi
  23. echo "开始提交并打版本标签..."
  24. echo "提交描述: $COMMIT_MESSAGE"
  25. echo "版本标签: $VERSION_TAG"
  26. # 添加所有更改到暂存区[citation:4][citation:6]
  27. git add .
  28. # 进行提交[citation:4][citation:10]
  29. git commit -m "$COMMIT_MESSAGE"
  30. if [ $? -ne 0 ]; then
  31. echo "错误: 提交失败。"
  32. exit 1
  33. fi
  34. # 创建轻量标签或附注标签(这里创建轻量标签)[citation:4]
  35. git tag "$VERSION_TAG"
  36. if [ $? -ne 0 ]; then
  37. echo "错误: 创建标签失败。"
  38. exit 1
  39. fi
  40. # 推送到远程仓库并推送标签[citation:4]
  41. echo "正在推送到远程仓库..."
  42. git push
  43. git push origin "$VERSION_TAG"
  44. echo "✅ 完成!提交已推送,版本标签 $VERSION_TAG 已创建并推送。"