Skip to content
Back to skills

Git Blame

ASecurity

代码追溯专家 - 查找代码修改者、关联PR、获取改动背景。 触发词: 谁改的, 谁写的, blame, 追溯, 找作者, 这行代码, 提交记录, 谁提交的, PR, 代码历史

  • 17 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added May 30, 2026
documentationbashazuregitdevops

Works with

  • mcp

Security analysis

A100/100

Scanned May 30, 2026

npx -y skills add gabrielmoreira/agent-skills-mirror --skill git-blame --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Git Blame?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Git Blame
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/gabrielmoreira-git-blame/badge)](https://www.skillsdirectory.com/skills/gabrielmoreira-git-blame)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: git-blame
description: |
  代码追溯专家 - 查找代码修改者、关联PR、获取改动背景。
  触发词: 谁改的, 谁写的, blame, 追溯, 找作者, 这行代码, 提交记录, 谁提交的, PR, 代码历史
---

# 代码追溯专家

> 帮助定位代码修改者,获取改动背景,便于协作解决问题

---

## 执行声明规范

### 开始执行时

```markdown
🔍 **正在执行: 代码追溯** (`#git-blame`)

✅ 已加载 Skill 指引
⭕ 当前步骤: 识别追溯目标
```

### 执行完成时

```markdown
✅ **执行完成**: 代码追溯

参考来源:
- Skill: `#git-blame`
- 数据来源: [本地 Git / MCP DevOps]

产出物: 代码追溯报告
```

---

## 适用场景

- Debug 时需要找到问题代码的作者
- 想了解某段代码为什么这样写
- 需要找到相关 PR 查看讨论上下文
- 想知道某个文件最近被谁修改过

---

## 工作流程

```
步骤1: 识别追溯目标
   ↓
步骤2: 执行代码追溯
   ↓
步骤3: 获取关联 PR
   ↓
步骤4: 输出追溯报告
```

---

## 执行步骤

### 步骤1: 识别追溯目标

**目标**: 确定要追溯的代码位置

**识别信息**:
- 文件路径
- 行号范围(可选)
- 代码片段(可选)

**判断代码位置**:

| 情况 | 处理方式 |
|------|---------|
| 工作区内的文件 | 使用本地 `git blame` |
| 远程仓库文件 | 使用 `mcp_azuredevops_list_commits` |
| 用户提供代码片段 | 先搜索定位,再追溯 |

### 步骤2: 执行代码追溯

#### 方式A: 本地 Git(工作区代码)

```bash
# 查看某行的提交信息
git blame -L <起始行>,<结束行> <文件路径>

# 查看提交详情
git show <commit-hash> --stat

# 查看提交的完整信息
git log -1 --format="%H%n%an%n%ae%n%s%n%b" <commit-hash>
```

#### 方式B: MCP DevOps(远程仓库)

```
调用: mcp_azuredevops_list_commits
参数:
  - repositoryId: 仓库名称
  - branchName: 分支名
  - top: 返回数量
```

从返回结果提取:
- `author.name` - 作者姓名
- `author.email` - 作者邮箱
- `comment` - 提交信息(含 PR 号)
- `files[].path` - 修改的文件
- `files[].patch` - 具体改动

### 步骤3: 获取关联 PR

**从 commit message 提取 PR 号**:

常见格式:
- `已合并 PR 236436: ...`
- `Merged PR 236436: ...`
- `(#236436)`

**获取 PR 详情**:

```
调用: mcp_azuredevops_get_pull_request_comments
参数:
  - repositoryId: 仓库名
  - pullRequestId: PR 号
```

### 步骤4: 输出追溯报告

使用以下模板输出结果:

---

## 输出模板

```markdown
## 🔍 代码追溯报告

### 📍 追溯目标
- **文件**: `path/to/file.cs`
- **行号**: L100-L110
- **代码片段**: [如有]

### 👤 修改者信息
| 字段 | 值 |
|------|-----|
| 作者 | [姓名] |
| 邮箱 | [email] |
| 时间 | [日期] |
| Commit | [hash 前8位] |

### 🔗 关联 PR
- **PR #[号码]**: [标题]
- **链接**: [DevOps 链接]

### 📝 改动说明
[commit message 或 PR 描述]

### 💬 PR 讨论摘要
[如果有评论]

### 📌 后续建议
- 联系 **[作者]** 了解改动背景
- 查看 PR 中的测试用例
- [其他建议]
```

---

## 常用命令速查

| 场景 | 命令 |
|------|------|
| 查看某行作者 | `git blame -L 100,110 file.cs` |
| 查看文件历史 | `git log --oneline -10 -- file.cs` |
| 查看提交详情 | `git show <hash>` |
| 查找包含关键词的提交 | `git log --grep="关键词" --oneline` |
| 查看某人的提交 | `git log --author="姓名" --oneline` |

---

## 相关 Skill

| Skill | 用途 |
|-------|------|
| `#expert-index` | 需要找对应模块专家时 |

---

## 注意事项

1. **隐私**: 仅展示工作相关信息,不泄露个人隐私
2. **沟通**: 找到作者后,建议先了解背景再提问
3. **上下文**: 关注 PR 讨论,可能有重要决策记录

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.