关于 changelog
从 Git 历史整理变更日志和发布说明的技能,介绍使用 Git 命令、GitHub CLI 和 Gemini 汇总变更并准备版本发布。
主要功能
- 01根据 Git 历史生成草稿
- 02比较不同标签间的提交
- 03按 Conventional Commits 类型归类
- 04创建 GitHub 发布说明
- 05查找破坏性变更
适用场景
- 01准备版本发布说明
- 02审阅某个标签以来的变更
- 03维护 CHANGELOG.md 文件
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ johnlindquist/ claude --skill changelog安装后在 Claude Code 中输入/changelog确认已加载。
详细介绍
变更日志生成器
从 git 提交生成变更日志并管理发布说明。
前置条件
# Git
git --version
# GitHub CLI (for release notes)
brew install gh
gh auth login
# Gemini (for AI summaries)
pip install google-generativeai
export GEMINI_API_KEY=your_api_key
命令行参考
Git 历史命令
# Recent commits
git log --oneline -20
# Since last tag
git log $(git describe --tags --abbrev=0)..HEAD --oneline
# Between tags
git log v1.0.0..v1.1.0 --oneline
# With full messages
git log v1.0.0..v1.1.0 --pretty=format:"%h %s%n%b"
# By author
git log --author="name" --oneline -10
# With dates
git log --format="%h %ad %s" --date=short
查找标签
# List all tags
git tag
# List tags with dates
git tag --sort=-creatordate --format='%(refname:short) %(creatordate:short)'
# Latest tag
git describe --tags --abbrev=0
# Tags matching pattern
git tag -l "v1.*"
生成变更日志
从 Git 日志生成
# Simple changelog since tag
git log v1.0.0..HEAD --oneline > CHANGELOG_DRAFT.md
# Categorized by conventional commits
git log v1.0.0..HEAD --oneline | grep "^[a-f0-9]* feat:"
git log v1.0.0..HEAD --oneline | grep "^[a-f0-9]* fix:"
git log v1.0.0..HEAD --oneline | grep "^[a-f0-9]* chore:"
使用 GitHub CLI
# Generate release notes
gh release create v1.1.0 --generate-notes
# View release notes draft
gh release create v1.1.0 --generate-notes --notes-start-tag v1.0.0 --dry-run
# From existing release
gh release view v1.0.0
AI 生成的变更日志
# Get commits since last tag
COMMITS=$(git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:"%s%n%b")
# Generate polished changelog
gemini -m pro -o text -e "" "Generate a changelog from these commits:
$COMMITS
Format as:
## [Version] - Date
### Added
- New features
### Changed
- Modifications
### Fixed
- Bug fixes
### Breaking Changes
- Any breaking changes
Write user-friendly descriptions, not raw commit messages."
工作流模式
发布准备
#!/bin/bash
VERSION=$1
LAST_TAG=$(git describe --tags --abbrev=0)
echo "# Release $VERSION"
echo ""
echo "Changes since $LAST_TAG:"
echo ""
# Categorize commits
echo "## Features"
git log $LAST_TAG..HEAD --oneline | grep -i "feat:" | sed 's/^[a-f0-9]* feat: /- /'
echo ""
echo "## Fixes"
git log $LAST_TAG..HEAD --oneline | grep -i "fix:" | sed 's/^[a-f0-9]* fix: /- /'
echo ""
echo "## Other"
git log $LAST_TAG..HEAD --oneline | grep -v -i "feat:\|fix:" | sed 's/^[a-f0-9]* /- /'
破坏性变更检测
# Find breaking changes in commit messages
git log v1.0.0..HEAD --oneline | grep -i "breaking\|BREAKING"
# Find in commit bodies
git log v1.0.0..HEAD --grep="BREAKING" --pretty=format:"%h %s"
维护 CHANGELOG.md
标准格式 (Keep a Changelog):
# Changelog
All notable changes to this project will be documented in this file.
## [Unreleased]
### Added
- New feature X
### Changed
- Updated Y
### Fixed
- Bug in Z
## [1.1.0] - 2024-01-15
### Added
- Feature A
- Feature B
### Fixed
- Issue #123
更新脚本
#!/bin/bash
VERSION=$1
DATE=$(date +%Y-%m-%d)
# Generate new section
NEW_SECTION="## [$VERSION] - $DATE
$(git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:"- %s")
"
# Prepend to changelog (after header)
head -7 CHANGELOG.md > CHANGELOG_NEW.md
echo "" >> CHANGELOG_NEW.md
echo "$NEW_SECTION" >> CHANGELOG_NEW.md
echo "" >> CHANGELOG_NEW.md
tail -n +8 CHANGELOG.md >> CHANGELOG_NEW.md
mv CHANGELOG_NEW.md CHANGELOG.md
统计
# Commits by author since tag
git shortlog -sn v1.0.0..HEAD
# Files changed
git diff --stat v1.0.0..HEAD | tail -1
# Commits per day
git log --format="%ad" --date=short v1.0.0..HEAD | sort | uniq -c
# Most changed files
git diff --stat v1.0.0..HEAD | sort -k3 -n -r | head -10
GitHub Releases
# Create release with notes
gh release create v1.1.0 --title "v1.1.0" --notes-file RELEASE_NOTES.md
# Create from tag with auto-notes
gh release create v1.1.0 --generate-notes
# Edit existing release
gh release edit v1.1.0 --notes-file UPDATED_NOTES.md
# List releases
gh release list
# Download release assets
gh release download v1.1.0
最佳实践
- 使用约定式提交 - 实现自动分类
- 为发布打标签 - 为变更日志提供清晰的边界
- 面向用户编写 - 将技术内容转化为用户影响
- 注明破坏性变更 - 显著标记
- 包含 issue 引用 - 链接到相关 issue
- 为发布标注日期 - 清晰的时间线
- 保留未发布部分 - 跟踪正在进行的工作
评论
支持 Markdown