#!/bin/bash # Git 工作区设置脚本 # 用于初始化 Git 工作流程 set -e echo "🚀 开始设置 Git 工作区..." # 检查是否在 Git 仓库中 if [ ! -d .git ]; then echo "❌ 当前目录不是 Git 仓库" echo "正在初始化 Git 仓库..." git init fi # 设置 Git 用户信息(如果未设置) if [ -z "$(git config user.name)" ]; then echo "📝 设置 Git 用户信息..." git config user.name "唐天洛" git config user.email "tianluo.tang@example.com" fi # 创建必要的目录 echo "📁 创建目录结构..." mkdir -p scripts backups logs # 添加 .gitignore(如果不存在) if [ ! -f .gitignore ]; then echo "📋 创建 .gitignore 文件..." cat > .gitignore << 'EOF' # 临时文件 *.tmp *.temp *.log *.bak *.swp *~ # Python 缓存 __pycache__/ *.py[cod] *$py.class .Python # 环境配置 .env .venv venv/ ENV/ env/ # 编辑器配置 .vscode/ .idea/ *.swp *.swo # 飞书同步缓存 feishu_sync_system/temp/ feishu_sync_system/backups/ *.feishu_backup # 小说数据 novel-tracker/*.json novel-tracker/*.lock novel_sync_state.json # 质量报告(保留主要报告,忽略临时报告) quality_reports/ quality_report_ch*.json # 小说章节备份 novel/backups/ novels/backups/ # 脚本生成的临时文件 *.sh.log *.py.out # 本地调试文件 /tmp/ /temp/ EOF fi # 设置 Git 别名 echo "⚡ 设置 Git 别名..." git config alias.co checkout git config alias.br branch git config alias.ci commit git config alias.st status git config alias.unstage 'reset HEAD --' git config alias.last 'log -1 HEAD' git config alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" # 创建提交信息模板 echo "📝 创建提交信息模板..." cat > .gitmessage << 'EOF' # (): # |<---- 使用最多 50 个字符 ---->| # # 解释为什么需要这个变更 # |<---- 尽量限制在 72 个字符内 ---->| # # 可选的 footer,用于关闭 issue 或提供额外信息 # 例如: Closes #123, #456, #789 # 类型 (type): # feat: 新功能 # fix: 修复 bug # docs: 文档更新 # style: 代码格式调整 # refactor: 代码重构 # test: 测试相关 # chore: 构建过程或辅助工具的变动 # perf: 性能优化 # ci: CI/CD 配置 # 范围 (scope): 可选,可以是文件、目录或功能模块 EOF git config commit.template .gitmessage echo "✅ Git 工作区设置完成!" echo "" echo "📋 下一步操作建议:" echo "1. 添加文件到暂存区: git add ." echo "2. 提交初始版本: git commit -m 'feat(init): 初始化工作区'" echo "3. 添加远程仓库: git remote add origin " echo "4. 推送到远程: git push -u origin main"