关于 git-ai-search
git-ai-search 是一项技能,可在 Git AI 历史中查找 AI 编码对话并恢复其上下文。开发者可查看提交或代码区域背后的提示词,也可在 Shell 或 Claude 中继续先前的会话。
主要功能
- 01按提交、文件、行或主题搜索会话
- 02按作者、工具和日期筛选
- 03查看完整提示词记录
- 04导出机器可读结果
- 05恢复上下文以继续工作
- 06携带恢复的上下文启动 Claude
适用场景
- 01追溯某次提交背后的 AI 辅助过程
- 02查找影响特定代码行的会话
- 03继续队友的 AI 编码会话
- 04审查拉取请求中的 AI 参与情况
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ git-ai-project/ git-ai --skill git-ai-search安装后在 Claude Code 中输入/git-ai-search确认已加载。
详细介绍
Git AI 搜索技能
使用 git-ai search 和 git-ai continue 搜索并恢复 git 历史记录中的 AI 对话上下文。
概述
Git AI 会追踪 AI 生成的代码及其对应的对话。此技能可帮助你:
- 搜索 - 按提交、文件、模式或作者查找 AI 提示词会话
- 继续 - 恢复 AI 会话上下文,接着完成他人未完成的工作
- 查看 - 查看特定提示词的完整记录
各命令的适用场景
| 你想要…… | 使用…… |
|---|---|
| 查看某个提交包含哪些 AI 上下文 | git-ai search --commit <sha> |
| 查看特定行的 AI 上下文 | git-ai search --file <path> --lines <range> |
| 阅读完整 AI 对话 | git-ai search --commit <sha> --verbose |
| 获取机器可读输出 | git-ai search --json |
| 查找提及某个主题的提示词 | git-ai search --pattern "keyword" |
| 继续某人的 AI 会话 | git-ai continue --commit <sha> |
| 继续处理某个代码区域 | git-ai continue --file <path> --lines <range> |
| 启动 Claude 并恢复上下文 | git-ai continue --commit <sha> --launch |
| 查看特定提示词的记录 | git-ai show-prompt <id> |
工作流模式
1. 调查提交
了解特定提交中使用了哪些 AI 辅助:
# See a summary of AI sessions in the commit
git-ai search --commit abc1234
# View the full conversations
git-ai search --commit abc1234 --verbose
# Get JSON for programmatic processing
git-ai search --commit abc1234 --json | jq '.prompts | keys[]'
2. 理解代码区域
查找对特定行有贡献的 AI 会话:
# Search by file
git-ai search --file src/main.rs
# Search specific lines
git-ai search --file src/main.rs --lines 100-150
# Multiple line ranges
git-ai search --file src/main.rs --lines 50-75 --lines 200-250
3. 继续他人的工作
从队友停下的地方接着做:
# See what they were working on
git-ai search --commit abc1234 --verbose
# Restore context and continue in your shell
git-ai continue --commit abc1234
# Or launch directly into Claude Code
git-ai continue --commit abc1234 --launch
# Or copy context to clipboard to paste elsewhere
git-ai continue --commit abc1234 --clipboard
4. 审查拉取请求
了解 PR 中的 AI 参与情况:
# Get all commits in the PR
COMMITS=$(gh pr view 123 --json commits -q '.commits[].oid')
# Search each commit
for sha in $COMMITS; do
echo "=== $sha ==="
git-ai search --commit $sha
done
# Or search the full range
BASE=$(gh pr view 123 --json baseRefOid -q '.baseRefOid')
HEAD=$(gh pr view 123 --json headRefOid -q '.headRefOid')
git-ai search --commit $BASE..$HEAD
5. 审计文件中的 AI 参与情况
查看所有修改过某个文件的 AI 会话:
# Full file history
git-ai search --file src/auth/login.rs
# Filter by author
git-ai search --file src/auth/login.rs --author "Alice"
# Filter by tool
git-ai search --file src/auth/login.rs --tool claude
6. 按主题搜索
查找讨论特定主题的提示词:
# Search prompt content
git-ai search --pattern "authentication"
git-ai search --pattern "error handling"
# Combine with filters
git-ai search --pattern "refactor" --tool cursor
7. 将输出传递给其他工具
与脚本和工作流集成:
# Get prompt IDs only
git-ai search --commit abc1234 --porcelain
# Count matches
git-ai search --file src/main.rs --count
# JSON for processing
git-ai search --commit abc1234 --json | jq '.prompts[] | {tool, model, author: .human_author}'
# Find commits with AI-authored code
git log --oneline | while read sha msg; do
count=$(git-ai search --commit $sha --count 2>/dev/null || echo "0")
if [ "$count" != "0" ]; then
echo "$sha ($count sessions): $msg"
fi
done
命令参考
git-ai search
按各种条件搜索 AI 提示词会话。
git-ai search [OPTIONS]
上下文来源(任选其一):
--commit <rev>- 搜索特定提交(或使用sha1..sha2指定范围)--file <path>- 按文件路径搜索--lines <range>- 限定行范围(需要 --file,可重复指定)--pattern <text>- 在提示词内容中进行全文搜索--prompt-id <id>- 按 ID 查找特定提示词
筛选条件(可组合):
--author <name>- 按人工作者筛选(子字符串匹配)--tool <name>- 按工具筛选(claude、cursor 等)--since <date>- 仅显示此日期之后的提示词--until <date>- 仅显示此日期之前的提示词
输出格式(任选其一):
- (默认)- 人类可读的摘要
--json- 完整 JSON 输出--verbose- 包含完整记录的详细输出--porcelain- 仅输出机器可读的提示词 ID--count- 仅显示匹配的提示词数量
git-ai continue
恢复 AI 会话上下文以继续工作。
git-ai continue [OPTIONS]
上下文来源(任选其一;使用 TUI 时也可不指定):
--commit <rev>- 从某个提交继续--file <path>- 从某个文件继续--lines <range>- 限定行范围(与 --file 配合使用)--prompt-id <id>- 继续特定提示词
Agent 选择:
--agent <name>- 目标 Agent(claude、cursor;默认:claude)--tool <name>- --agent 的别名
输出模式(任选其一):
- (默认)- 将格式化后的上下文输出到标准输出
--launch- 启动 Agent CLI 并载入上下文--clipboard- 将上下文复制到剪贴板--json- 以结构化 JSON 格式输出
选项:
--max-messages <n>- 限制每个提示词的消息数量(默认:50)
git-ai show-prompt
显示特定提示词的完整记录。
git-ai show-prompt <prompt_id> [OPTIONS]
--json- 以 JSON 格式输出--raw- 显示原始内部格式
输出格式
默认输出
人类可读的摘要:
Found 2 AI prompt session(s) for commit abc1234
[1] Prompt a1b2c3d4 (claude / claude-sonnet-4)
Author: Alice
Files: src/main.rs:10-50
[2] Prompt e5f6g7h8 (cursor / gpt-4)
Author: Bob
Files: src/lib.rs:100-150, src/utils.rs:20-30
--json 输出
供程序使用的完整结构化数据:
{
"source": {
"sha": "abc1234",
"author": "Alice",
"date": "2025-01-15",
"message": "Add authentication"
},
"prompts": [
{
"id": "a1b2c3d4",
"tool": "claude",
"model": "claude-sonnet-4",
"author": "Alice",
"messages": [...]
}
]
}
--verbose 输出
内联显示完整对话:
=== Session 1: Prompt a1b2c3d4 ===
Tool: claude (claude-sonnet-4)
Author: Alice
**User**:
Help me implement user authentication...
**Assistant**:
I'll help you implement authentication. Here's my approach...
--porcelain 输出
每行一个提示词 ID(用于脚本):
a1b2c3d4
e5f6g7h8
--count 输出
仅显示数量:
2
提示
组合筛选条件
筛选条件采用 AND 语义——提示词必须匹配所有指定的筛选条件:
# Claude prompts by Alice in the last 7 days
git-ai search --commit HEAD~10..HEAD --tool claude --author "Alice" --since 7d
与 Git 命令搭配使用
与 git log 组合使用以探索历史记录:
# Find commits with high AI involvement
git log --oneline --since="1 week ago" | while read sha msg; do
git-ai search --commit $sha --count 2>/dev/null
done
# Search AI context for files changed in a commit
git diff-tree --no-commit-id --name-only -r abc1234 | while read file; do
git-ai search --file "$file"
done
为不同的 Agent 恢复上下文
--agent 标志用于控制上下文的格式:
# For Claude Code
git-ai continue --commit abc1234 --agent claude --launch
# For other tools, copy to clipboard
git-ai continue --commit abc1234 --clipboard
检查特定提示词
如果搜索结果太多,可进一步深入查看:
# Get the IDs
git-ai search --commit abc1234 --porcelain
# View a specific one
git-ai show-prompt a1b2c3d4
性能提示
- 使用
--commit可获得最快结果(直接查找注释) --file需要计算 blame(对于大型文件会比较慢)--pattern会搜索数据库(快速匹配子字符串)- 先添加
--count,以便在输出详细内容前检查结果数量
示例
快速检查
# Any AI in this commit?
git-ai search --commit HEAD --count
# What tools were used?
git-ai search --commit abc1234 --json | jq '.prompts[].tool' | sort -u
# Who used AI in this file?
git-ai search --file src/main.rs --json | jq '.prompts[].author' | sort -u
详细探索
# Full context of the most recent AI session
git-ai search --commit HEAD --verbose | head -100
# Continue the exact session that wrote these lines
git-ai continue --file src/main.rs --lines 50-100 --launch
与 CI/CD 集成
# In a PR check, report AI involvement
PROMPT_COUNT=$(git-ai search --commit $PR_HEAD --count 2>/dev/null || echo "0")
if [ "$PROMPT_COUNT" -gt 0 ]; then
echo "This PR includes $PROMPT_COUNT AI-assisted session(s)"
git-ai search --commit $PR_HEAD
fi
评论
支持 Markdown