novel-doomsday-resurgence/scripts/git-setup.sh
唐天洛 bc9188b0fd feat(git-workflow): 添加 Git 工作流和脚本
包含:
- GIT_WORKFLOW.md - 详细的 Git 工作流规范
- scripts/git-setup.sh - Git 工作区初始化脚本
- scripts/git-daily.sh - 日常 Git 管理脚本
- scripts/git-novel-workflow.sh - 小说专用 Git 工作流
- 更新 .gitignore 排除子仓库的 .git 目录
- 添加 novel-tracker/ 目录
- 添加 projects/ 目录(排除子仓库 .git)
- 添加 tomato-novel/ 目录
2026-03-30 15:50:36 +08:00

131 lines
2.8 KiB
Bash
Executable File
Raw Permalink 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
# 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'
# <type>(<scope>): <subject>
# |<---- 使用最多 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 <your-repo-url>"
echo "4. 推送到远程: git push -u origin main"