lint.md
4.66 KB
根据我对你的 monorepo 仓库的分析,你的项目已经配置了一套完善的 git 管理方案。这里为你详细介绍如何统一管理子应用的提交和改动记录:
📋 当前仓库已有的配置
你的仓库已经配置了以下工具:
- commitlint + czg(commitizen-git) - 规范化提交信息
- lefthook - Git hooks 管理
- changeset - 版本管理和变更日志
- pnpm workspace + turbo - Monorepo 构建管理
🎯 推荐的子应用提交管理方案
1. 使用规范化提交信息(已配置)
你的仓库已配置了 commitlint,提交时使用 scope 来标识具体的子应用:
# 使用交互式提交命令
pnpm commit
# 提交格式示例:
feat(scrm-base): 添加用户管理功能
fix(micro-app-template): 修复路由跳转问题
chore(scrm-base): 更新依赖包
查看你的配置文件,系统会自动检测改动的包,并提供可选的 scope 列表。
2. 查看特定子应用的提交历史
# 查看 scrm-base 应用的所有提交
git log --all --oneline -- apps/frontend-micro/scrm-base
# 查看详细提交信息
git log --all -- apps/frontend-micro/scrm-base
# 只查看提交信息(不显示 diff)
git log --oneline --grep="scrm-base"
# 查看某个应用最近10次提交
git log --oneline -n 10 -- apps/frontend-micro/scrm-base
# 查看某个时间段内的提交
git log --since="2024-01-01" --until="2024-12-31" -- apps/frontend-micro/scrm-base
# 生成变更统计
git log --stat -- apps/frontend-micro/scrm-base
3. 使用 Changeset 管理变更(已配置)
当你修改某个子应用后,创建 changeset 来记录变更:
# 创建变更记录
pnpm changeset
# 系统会提示你:
# 1. 选择受影响的包(子应用)
# 2. 选择版本变更类型(major/minor/patch)
# 3. 编写变更说明
4. 实用的 Git 别名配置
在项目根目录或全局 .gitconfig 中添加:
# 添加到 .git/config 或 ~/.gitconfig
[alias]
# 查看指定应用的提交日志
app-log = "!f() { git log --oneline --all -- apps/frontend-micro/$1; }; f"
# 查看指定应用的详细变更
app-diff = "!f() { git diff -- apps/frontend-micro/$1; }; f"
# 查看指定应用未提交的变更
app-status = "!f() { git status -- apps/frontend-micro/$1; }; f"
# 只暂存指定应用的变更
app-add = "!f() { git add apps/frontend-micro/$1; }; f"
使用示例:
git app-log scrm-base
git app-diff scrm-base
5. 查看子应用的文件变更统计
# 查看 scrm-base 应用的贡献者统计
git shortlog -sn -- apps/frontend-micro/scrm-base
# 查看代码行数变更
git log --numstat --pretty="%H" -- apps/frontend-micro/scrm-base | awk 'NF==3 {plus+=$1; minus+=$2} END {printf("+%d, -%d\n", plus, minus)}'
# 查看最近修改的文件
git log --name-only --pretty="" -- apps/frontend-micro/scrm-base | sort | uniq
6. 创建子应用发布标签
# 为特定子应用创建标签
git tag -a scrm-base-v1.0.0 -m "scrm-base: 发布 v1.0.0"
# 推送标签
git push origin scrm-base-v1.0.0
# 查看某个应用的所有标签
git tag -l "scrm-base-*"
7. 生成子应用变更日志
创建一个脚本 scripts/changelog.sh:
#!/bin/bash
APP_NAME=$1
OUTPUT_FILE="apps/frontend-micro/$APP_NAME/CHANGELOG.md"
echo "# Changelog for $APP_NAME" > $OUTPUT_FILE
echo "" >> $OUTPUT_FILE
git log --pretty=format:"- %s (%h) - %an, %ar" -- apps/frontend-micro/$APP_NAME >> $OUTPUT_FILE
使用:
bash scripts/changelog.sh scrm-base
8. 使用过滤分支工作(高级)
如果需要更系统的管理,可以使用 git sparse-checkout:
# 只检出特定子应用(用于性能优化)
git sparse-checkout init --cone
git sparse-checkout set apps/frontend-micro/scrm-base
📊 推荐的工作流程
# 1. 修改代码后,查看当前应用的改动
git status apps/frontend-micro/scrm-base
# 2. 使用规范化提交
pnpm commit
# 选择 type: feat/fix/etc
# 选择 scope: scrm-base
# 填写描述
# 3. 创建 changeset(可选,用于版本发布)
pnpm changeset
# 4. 推送代码
git push
# 5. 查看该应用的提交历史
git log --oneline --all -- apps/frontend-micro/scrm-base
🔍 查看跨应用的影响
# 查看同时修改了多个应用的提交
git log --oneline --all --format="%h %s" | grep -E "(scrm-base|micro-app-template)"
# 查看某次提交影响了哪些应用
git show <commit-hash> --stat | grep "apps/frontend-micro"
你的仓库配置已经很完善了,只需要按照规范使用 pnpm commit 命令并正确选择 scope,就能很好地管理各个子应用的提交记录。