code-abyss 1.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +197 -0
- package/bin/install.js +193 -0
- package/bin/uninstall.js +42 -0
- package/config/AGENTS.md +247 -0
- package/config/CLAUDE.md +207 -0
- package/config/settings.example.json +27 -0
- package/output-styles/abyss-cultivator.md +399 -0
- package/package.json +41 -0
- package/skills/SKILL.md +115 -0
- package/skills/ai/SKILL.md +29 -0
- package/skills/ai/agent-dev.md +242 -0
- package/skills/ai/llm-security.md +288 -0
- package/skills/architecture/SKILL.md +41 -0
- package/skills/architecture/api-design.md +225 -0
- package/skills/architecture/caching.md +299 -0
- package/skills/architecture/cloud-native.md +285 -0
- package/skills/architecture/compliance.md +299 -0
- package/skills/architecture/data-security.md +184 -0
- package/skills/architecture/message-queue.md +329 -0
- package/skills/architecture/security-arch.md +210 -0
- package/skills/development/SKILL.md +43 -0
- package/skills/development/cpp.md +246 -0
- package/skills/development/go.md +323 -0
- package/skills/development/java.md +277 -0
- package/skills/development/python.md +288 -0
- package/skills/development/rust.md +313 -0
- package/skills/development/shell.md +313 -0
- package/skills/development/typescript.md +277 -0
- package/skills/devops/SKILL.md +36 -0
- package/skills/devops/cost-optimization.md +272 -0
- package/skills/devops/database.md +217 -0
- package/skills/devops/devsecops.md +198 -0
- package/skills/devops/git-workflow.md +181 -0
- package/skills/devops/observability.md +280 -0
- package/skills/devops/performance.md +273 -0
- package/skills/devops/testing.md +186 -0
- package/skills/gen-docs/SKILL.md +114 -0
- package/skills/gen-docs/scripts/doc_generator.py +491 -0
- package/skills/multi-agent/SKILL.md +268 -0
- package/skills/run_skill.py +88 -0
- package/skills/security/SKILL.md +51 -0
- package/skills/security/blue-team.md +379 -0
- package/skills/security/code-audit.md +265 -0
- package/skills/security/pentest.md +226 -0
- package/skills/security/red-team.md +321 -0
- package/skills/security/threat-intel.md +322 -0
- package/skills/security/vuln-research.md +369 -0
- package/skills/tests/README.md +225 -0
- package/skills/tests/SUMMARY.md +362 -0
- package/skills/tests/__init__.py +3 -0
- package/skills/tests/test_change_analyzer.py +558 -0
- package/skills/tests/test_doc_generator.py +538 -0
- package/skills/tests/test_module_scanner.py +376 -0
- package/skills/tests/test_quality_checker.py +516 -0
- package/skills/tests/test_security_scanner.py +426 -0
- package/skills/verify-change/SKILL.md +138 -0
- package/skills/verify-change/scripts/change_analyzer.py +529 -0
- package/skills/verify-module/SKILL.md +125 -0
- package/skills/verify-module/scripts/module_scanner.py +321 -0
- package/skills/verify-quality/SKILL.md +158 -0
- package/skills/verify-quality/scripts/quality_checker.py +481 -0
- package/skills/verify-security/SKILL.md +141 -0
- package/skills/verify-security/scripts/security_scanner.py +368 -0
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: database
|
|
3
|
+
description: 数据库设计与优化。SQL、NoSQL、索引、查询优化。当用户提到数据库、SQL、PostgreSQL、MySQL、MongoDB、Redis时使用。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# 🔧 炼器秘典 · 数据库
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## SQL 基础
|
|
10
|
+
|
|
11
|
+
### 查询
|
|
12
|
+
```sql
|
|
13
|
+
-- 基础查询
|
|
14
|
+
SELECT id, name, email
|
|
15
|
+
FROM users
|
|
16
|
+
WHERE status = 'active'
|
|
17
|
+
ORDER BY created_at DESC
|
|
18
|
+
LIMIT 10 OFFSET 0;
|
|
19
|
+
|
|
20
|
+
-- 聚合
|
|
21
|
+
SELECT department, COUNT(*) as count, AVG(salary) as avg_salary
|
|
22
|
+
FROM employees
|
|
23
|
+
GROUP BY department
|
|
24
|
+
HAVING COUNT(*) > 5;
|
|
25
|
+
|
|
26
|
+
-- 连接
|
|
27
|
+
SELECT u.name, o.total
|
|
28
|
+
FROM users u
|
|
29
|
+
INNER JOIN orders o ON u.id = o.user_id
|
|
30
|
+
WHERE o.created_at > '2024-01-01';
|
|
31
|
+
|
|
32
|
+
-- 子查询
|
|
33
|
+
SELECT * FROM users
|
|
34
|
+
WHERE id IN (
|
|
35
|
+
SELECT user_id FROM orders
|
|
36
|
+
WHERE total > 1000
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
-- CTE
|
|
40
|
+
WITH active_users AS (
|
|
41
|
+
SELECT * FROM users WHERE status = 'active'
|
|
42
|
+
)
|
|
43
|
+
SELECT * FROM active_users WHERE created_at > '2024-01-01';
|
|
44
|
+
|
|
45
|
+
-- 窗口函数
|
|
46
|
+
SELECT name, salary,
|
|
47
|
+
RANK() OVER (PARTITION BY department ORDER BY salary DESC) as rank
|
|
48
|
+
FROM employees;
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
### 索引
|
|
52
|
+
```sql
|
|
53
|
+
-- 创建索引
|
|
54
|
+
CREATE INDEX idx_users_email ON users(email);
|
|
55
|
+
CREATE INDEX idx_orders_user_date ON orders(user_id, created_at);
|
|
56
|
+
CREATE UNIQUE INDEX idx_users_email_unique ON users(email);
|
|
57
|
+
|
|
58
|
+
-- 部分索引
|
|
59
|
+
CREATE INDEX idx_active_users ON users(email) WHERE status = 'active';
|
|
60
|
+
|
|
61
|
+
-- 查看执行计划
|
|
62
|
+
EXPLAIN ANALYZE SELECT * FROM users WHERE email = 'test@example.com';
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### 索引策略
|
|
66
|
+
```yaml
|
|
67
|
+
适合索引:
|
|
68
|
+
- WHERE 条件列
|
|
69
|
+
- JOIN 关联列
|
|
70
|
+
- ORDER BY 排序列
|
|
71
|
+
- 高选择性列
|
|
72
|
+
|
|
73
|
+
不适合索引:
|
|
74
|
+
- 频繁更新的列
|
|
75
|
+
- 低选择性列 (如性别)
|
|
76
|
+
- 小表
|
|
77
|
+
|
|
78
|
+
复合索引:
|
|
79
|
+
- 最左前缀原则
|
|
80
|
+
- 选择性高的列在前
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## PostgreSQL
|
|
84
|
+
|
|
85
|
+
### 特性
|
|
86
|
+
```sql
|
|
87
|
+
-- JSON 支持
|
|
88
|
+
SELECT data->>'name' as name
|
|
89
|
+
FROM users
|
|
90
|
+
WHERE data @> '{"status": "active"}';
|
|
91
|
+
|
|
92
|
+
-- 数组
|
|
93
|
+
SELECT * FROM posts
|
|
94
|
+
WHERE tags @> ARRAY['python', 'web'];
|
|
95
|
+
|
|
96
|
+
-- 全文搜索
|
|
97
|
+
SELECT * FROM articles
|
|
98
|
+
WHERE to_tsvector('english', content) @@ to_tsquery('python & web');
|
|
99
|
+
|
|
100
|
+
-- UPSERT
|
|
101
|
+
INSERT INTO users (email, name)
|
|
102
|
+
VALUES ('test@example.com', 'Test')
|
|
103
|
+
ON CONFLICT (email)
|
|
104
|
+
DO UPDATE SET name = EXCLUDED.name;
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## MySQL
|
|
108
|
+
|
|
109
|
+
### 特性
|
|
110
|
+
```sql
|
|
111
|
+
-- 全文搜索
|
|
112
|
+
SELECT * FROM articles
|
|
113
|
+
WHERE MATCH(title, content) AGAINST('python web' IN NATURAL LANGUAGE MODE);
|
|
114
|
+
|
|
115
|
+
-- JSON
|
|
116
|
+
SELECT JSON_EXTRACT(data, '$.name') as name
|
|
117
|
+
FROM users
|
|
118
|
+
WHERE JSON_EXTRACT(data, '$.status') = 'active';
|
|
119
|
+
|
|
120
|
+
-- 分区表
|
|
121
|
+
CREATE TABLE orders (
|
|
122
|
+
id INT,
|
|
123
|
+
created_at DATE
|
|
124
|
+
) PARTITION BY RANGE (YEAR(created_at)) (
|
|
125
|
+
PARTITION p2023 VALUES LESS THAN (2024),
|
|
126
|
+
PARTITION p2024 VALUES LESS THAN (2025)
|
|
127
|
+
);
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## NoSQL
|
|
131
|
+
|
|
132
|
+
### MongoDB
|
|
133
|
+
```javascript
|
|
134
|
+
// 查询
|
|
135
|
+
db.users.find({ status: "active" })
|
|
136
|
+
db.users.find({ age: { $gt: 18 } })
|
|
137
|
+
db.users.find({ tags: { $in: ["python", "web"] } })
|
|
138
|
+
|
|
139
|
+
// 聚合
|
|
140
|
+
db.orders.aggregate([
|
|
141
|
+
{ $match: { status: "completed" } },
|
|
142
|
+
{ $group: { _id: "$user_id", total: { $sum: "$amount" } } },
|
|
143
|
+
{ $sort: { total: -1 } },
|
|
144
|
+
{ $limit: 10 }
|
|
145
|
+
])
|
|
146
|
+
|
|
147
|
+
// 索引
|
|
148
|
+
db.users.createIndex({ email: 1 }, { unique: true })
|
|
149
|
+
db.users.createIndex({ location: "2dsphere" })
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
### Redis
|
|
153
|
+
```bash
|
|
154
|
+
# 字符串
|
|
155
|
+
SET key value
|
|
156
|
+
GET key
|
|
157
|
+
SETEX key 3600 value # 带过期时间
|
|
158
|
+
|
|
159
|
+
# 哈希
|
|
160
|
+
HSET user:1 name "Alice" email "alice@example.com"
|
|
161
|
+
HGET user:1 name
|
|
162
|
+
HGETALL user:1
|
|
163
|
+
|
|
164
|
+
# 列表
|
|
165
|
+
LPUSH queue task1
|
|
166
|
+
RPOP queue
|
|
167
|
+
|
|
168
|
+
# 集合
|
|
169
|
+
SADD tags python web
|
|
170
|
+
SMEMBERS tags
|
|
171
|
+
SINTER tags1 tags2
|
|
172
|
+
|
|
173
|
+
# 有序集合
|
|
174
|
+
ZADD leaderboard 100 user1
|
|
175
|
+
ZRANGE leaderboard 0 9 WITHSCORES
|
|
176
|
+
|
|
177
|
+
# 过期
|
|
178
|
+
EXPIRE key 3600
|
|
179
|
+
TTL key
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
## 查询优化
|
|
183
|
+
|
|
184
|
+
```yaml
|
|
185
|
+
原则:
|
|
186
|
+
- 只查询需要的列
|
|
187
|
+
- 避免 SELECT *
|
|
188
|
+
- 使用索引
|
|
189
|
+
- 避免全表扫描
|
|
190
|
+
- 分页查询
|
|
191
|
+
|
|
192
|
+
技巧:
|
|
193
|
+
- EXPLAIN 分析执行计划
|
|
194
|
+
- 避免在索引列上使用函数
|
|
195
|
+
- 使用覆盖索引
|
|
196
|
+
- 批量操作代替循环
|
|
197
|
+
- 合理使用缓存
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## 数据库设计
|
|
201
|
+
|
|
202
|
+
```yaml
|
|
203
|
+
范式:
|
|
204
|
+
- 1NF: 原子性
|
|
205
|
+
- 2NF: 消除部分依赖
|
|
206
|
+
- 3NF: 消除传递依赖
|
|
207
|
+
|
|
208
|
+
反范式:
|
|
209
|
+
- 适当冗余提高查询性能
|
|
210
|
+
- 读多写少场景
|
|
211
|
+
|
|
212
|
+
命名规范:
|
|
213
|
+
- 表名: 复数小写 (users, orders)
|
|
214
|
+
- 列名: 小写下划线 (created_at)
|
|
215
|
+
- 索引: idx_表名_列名
|
|
216
|
+
```
|
|
217
|
+
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: devsecops
|
|
3
|
+
description: DevSecOps。CI/CD安全、供应链安全、合规自动化。当用户提到 DevSecOps、CI/CD、供应链安全、SAST、DAST时使用。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# 🔧 炼器秘典 · DevSecOps
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## 安全左移
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
┌─────────────────────────────────────────────────────────────┐
|
|
13
|
+
│ 安全左移 │
|
|
14
|
+
├─────────────────────────────────────────────────────────────┤
|
|
15
|
+
│ 计划 → 编码 → 构建 → 测试 → 发布 → 部署 → 运维 → 监控 │
|
|
16
|
+
│ │ │ │ │ │ │ │ │ │
|
|
17
|
+
│ 威胁 SAST SCA DAST 签名 配置 日志 告警 │
|
|
18
|
+
│ 建模 IDE 依赖 渗透 验证 加固 审计 响应 │
|
|
19
|
+
└─────────────────────────────────────────────────────────────┘
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## CI/CD 安全
|
|
23
|
+
|
|
24
|
+
### GitHub Actions
|
|
25
|
+
```yaml
|
|
26
|
+
name: Security Pipeline
|
|
27
|
+
|
|
28
|
+
on: [push, pull_request]
|
|
29
|
+
|
|
30
|
+
jobs:
|
|
31
|
+
security:
|
|
32
|
+
runs-on: ubuntu-latest
|
|
33
|
+
steps:
|
|
34
|
+
- uses: actions/checkout@v4
|
|
35
|
+
|
|
36
|
+
# SAST - 静态分析
|
|
37
|
+
- name: Run Semgrep
|
|
38
|
+
uses: returntocorp/semgrep-action@v1
|
|
39
|
+
with:
|
|
40
|
+
config: p/security-audit
|
|
41
|
+
|
|
42
|
+
# SCA - 依赖扫描
|
|
43
|
+
- name: Run Trivy
|
|
44
|
+
uses: aquasecurity/trivy-action@master
|
|
45
|
+
with:
|
|
46
|
+
scan-type: 'fs'
|
|
47
|
+
severity: 'CRITICAL,HIGH'
|
|
48
|
+
|
|
49
|
+
# Secret 扫描
|
|
50
|
+
- name: Run Gitleaks
|
|
51
|
+
uses: gitleaks/gitleaks-action@v2
|
|
52
|
+
|
|
53
|
+
# 容器扫描
|
|
54
|
+
- name: Build and scan image
|
|
55
|
+
run: |
|
|
56
|
+
docker build -t myapp:${{ github.sha }} .
|
|
57
|
+
trivy image myapp:${{ github.sha }}
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### GitLab CI
|
|
61
|
+
```yaml
|
|
62
|
+
stages:
|
|
63
|
+
- test
|
|
64
|
+
- security
|
|
65
|
+
- build
|
|
66
|
+
- deploy
|
|
67
|
+
|
|
68
|
+
sast:
|
|
69
|
+
stage: security
|
|
70
|
+
image: semgrep/semgrep
|
|
71
|
+
script:
|
|
72
|
+
- semgrep --config=p/security-audit .
|
|
73
|
+
|
|
74
|
+
dependency_scan:
|
|
75
|
+
stage: security
|
|
76
|
+
image: aquasec/trivy
|
|
77
|
+
script:
|
|
78
|
+
- trivy fs --severity HIGH,CRITICAL .
|
|
79
|
+
|
|
80
|
+
container_scan:
|
|
81
|
+
stage: security
|
|
82
|
+
image: aquasec/trivy
|
|
83
|
+
script:
|
|
84
|
+
- trivy image $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## 安全扫描工具
|
|
88
|
+
|
|
89
|
+
### SAST (静态分析)
|
|
90
|
+
```yaml
|
|
91
|
+
工具:
|
|
92
|
+
- Semgrep: 多语言,规则丰富
|
|
93
|
+
- SonarQube: 企业级
|
|
94
|
+
- CodeQL: GitHub 原生
|
|
95
|
+
- Bandit: Python 专用
|
|
96
|
+
|
|
97
|
+
集成:
|
|
98
|
+
- IDE 插件
|
|
99
|
+
- Pre-commit hooks
|
|
100
|
+
- CI/CD pipeline
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### SCA (依赖扫描)
|
|
104
|
+
```yaml
|
|
105
|
+
工具:
|
|
106
|
+
- Trivy: 全能扫描
|
|
107
|
+
- Snyk: 商业方案
|
|
108
|
+
- OWASP Dependency-Check
|
|
109
|
+
- npm audit / pip-audit
|
|
110
|
+
|
|
111
|
+
检查项:
|
|
112
|
+
- 已知漏洞 (CVE)
|
|
113
|
+
- 许可证合规
|
|
114
|
+
- 过期依赖
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### DAST (动态分析)
|
|
118
|
+
```yaml
|
|
119
|
+
工具:
|
|
120
|
+
- OWASP ZAP
|
|
121
|
+
- Nuclei
|
|
122
|
+
- Burp Suite
|
|
123
|
+
|
|
124
|
+
集成:
|
|
125
|
+
- 部署后自动扫描
|
|
126
|
+
- 定期扫描
|
|
127
|
+
- PR 环境扫描
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## 供应链安全
|
|
131
|
+
|
|
132
|
+
### 依赖管理
|
|
133
|
+
```yaml
|
|
134
|
+
原则:
|
|
135
|
+
- 锁定依赖版本
|
|
136
|
+
- 定期更新
|
|
137
|
+
- 审查新依赖
|
|
138
|
+
- 使用私有仓库
|
|
139
|
+
|
|
140
|
+
工具:
|
|
141
|
+
- Dependabot
|
|
142
|
+
- Renovate
|
|
143
|
+
- Snyk
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
### 镜像安全
|
|
147
|
+
```yaml
|
|
148
|
+
原则:
|
|
149
|
+
- 使用官方基础镜像
|
|
150
|
+
- 最小化镜像
|
|
151
|
+
- 扫描漏洞
|
|
152
|
+
- 签名验证
|
|
153
|
+
|
|
154
|
+
工具:
|
|
155
|
+
- Trivy
|
|
156
|
+
- Cosign (签名)
|
|
157
|
+
- Notary
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### SBOM (软件物料清单)
|
|
161
|
+
```bash
|
|
162
|
+
# 生成 SBOM
|
|
163
|
+
syft packages dir:. -o spdx-json > sbom.json
|
|
164
|
+
|
|
165
|
+
# 扫描 SBOM
|
|
166
|
+
grype sbom:sbom.json
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## 安全门禁
|
|
170
|
+
|
|
171
|
+
```yaml
|
|
172
|
+
阻断条件:
|
|
173
|
+
- Critical 漏洞
|
|
174
|
+
- 高危依赖
|
|
175
|
+
- Secret 泄露
|
|
176
|
+
- 许可证违规
|
|
177
|
+
|
|
178
|
+
警告条件:
|
|
179
|
+
- High 漏洞
|
|
180
|
+
- 中危依赖
|
|
181
|
+
- 代码质量问题
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## 合规自动化
|
|
185
|
+
|
|
186
|
+
```yaml
|
|
187
|
+
检查项:
|
|
188
|
+
- CIS Benchmark
|
|
189
|
+
- PCI DSS
|
|
190
|
+
- SOC 2
|
|
191
|
+
- GDPR
|
|
192
|
+
|
|
193
|
+
工具:
|
|
194
|
+
- Open Policy Agent (OPA)
|
|
195
|
+
- Checkov
|
|
196
|
+
- Terrascan
|
|
197
|
+
```
|
|
198
|
+
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: git-workflow
|
|
3
|
+
description: Git 版本控制。分支管理、合并策略、GitHub工作流。当用户提到 Git、分支、merge、rebase、PR、GitHub时使用。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# 🔧 炼器秘典 · Git 工作流
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## 基础命令
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# 初始化
|
|
13
|
+
git init
|
|
14
|
+
git clone <url>
|
|
15
|
+
|
|
16
|
+
# 日常操作
|
|
17
|
+
git add <file>
|
|
18
|
+
git commit -m "message"
|
|
19
|
+
git push origin main
|
|
20
|
+
git pull origin main
|
|
21
|
+
|
|
22
|
+
# 状态查看
|
|
23
|
+
git status
|
|
24
|
+
git log --oneline -10
|
|
25
|
+
git diff
|
|
26
|
+
git diff --staged
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## 分支管理
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# 创建切换
|
|
33
|
+
git branch feature-x
|
|
34
|
+
git checkout feature-x
|
|
35
|
+
git checkout -b feature-x # 创建并切换
|
|
36
|
+
|
|
37
|
+
# 查看
|
|
38
|
+
git branch -a # 所有分支
|
|
39
|
+
git branch -vv # 详细信息
|
|
40
|
+
|
|
41
|
+
# 删除
|
|
42
|
+
git branch -d feature-x # 已合并
|
|
43
|
+
git branch -D feature-x # 强制删除
|
|
44
|
+
git push origin --delete feature-x # 远程
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## 分支策略
|
|
48
|
+
|
|
49
|
+
### Git Flow
|
|
50
|
+
```
|
|
51
|
+
main ─────────────────────────────────────────
|
|
52
|
+
│ ↑
|
|
53
|
+
└─ develop ─────────────────────────┬─
|
|
54
|
+
│ ↑ ↑ │
|
|
55
|
+
└─ feature/xxx ─────┘ │
|
|
56
|
+
└─ release/1.0 ────────────────┘
|
|
57
|
+
└─ hotfix/xxx ─────────────────┘
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
### GitHub Flow
|
|
61
|
+
```
|
|
62
|
+
main ─────────────────────────────────────────
|
|
63
|
+
│ ↑
|
|
64
|
+
└─ feature ────┘ (PR + Review + Merge)
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
### Trunk Based
|
|
68
|
+
```
|
|
69
|
+
main ─────────────────────────────────────────
|
|
70
|
+
│ ↑ ↑ ↑
|
|
71
|
+
└────┴────┴────┘ (短生命周期分支)
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
## 合并策略
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
# Merge (保留历史)
|
|
78
|
+
git checkout main
|
|
79
|
+
git merge feature-x
|
|
80
|
+
|
|
81
|
+
# Rebase (线性历史)
|
|
82
|
+
git checkout feature-x
|
|
83
|
+
git rebase main
|
|
84
|
+
git checkout main
|
|
85
|
+
git merge feature-x
|
|
86
|
+
|
|
87
|
+
# Squash (压缩提交)
|
|
88
|
+
git merge --squash feature-x
|
|
89
|
+
git commit -m "Feature X"
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## 冲突解决
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
# 1. 拉取最新
|
|
96
|
+
git fetch origin
|
|
97
|
+
git rebase origin/main
|
|
98
|
+
|
|
99
|
+
# 2. 解决冲突
|
|
100
|
+
# 编辑冲突文件,删除 <<<< ==== >>>> 标记
|
|
101
|
+
|
|
102
|
+
# 3. 继续
|
|
103
|
+
git add .
|
|
104
|
+
git rebase --continue
|
|
105
|
+
|
|
106
|
+
# 放弃
|
|
107
|
+
git rebase --abort
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
## 撤销操作
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
# 撤销工作区修改
|
|
114
|
+
git checkout -- <file>
|
|
115
|
+
git restore <file>
|
|
116
|
+
|
|
117
|
+
# 撤销暂存
|
|
118
|
+
git reset HEAD <file>
|
|
119
|
+
git restore --staged <file>
|
|
120
|
+
|
|
121
|
+
# 撤销提交
|
|
122
|
+
git reset --soft HEAD~1 # 保留修改
|
|
123
|
+
git reset --hard HEAD~1 # 丢弃修改
|
|
124
|
+
git revert <commit> # 新提交撤销
|
|
125
|
+
|
|
126
|
+
# 修改最后提交
|
|
127
|
+
git commit --amend
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
## Commit 规范
|
|
131
|
+
|
|
132
|
+
```yaml
|
|
133
|
+
格式: <type>(<scope>): <subject>
|
|
134
|
+
|
|
135
|
+
类型:
|
|
136
|
+
- feat: 新功能
|
|
137
|
+
- fix: 修复
|
|
138
|
+
- docs: 文档
|
|
139
|
+
- style: 格式
|
|
140
|
+
- refactor: 重构
|
|
141
|
+
- test: 测试
|
|
142
|
+
- chore: 构建/工具
|
|
143
|
+
|
|
144
|
+
示例:
|
|
145
|
+
- feat(auth): add JWT authentication
|
|
146
|
+
- fix(api): handle null response
|
|
147
|
+
- docs(readme): update installation guide
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## GitHub 工作流
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
# Fork 工作流
|
|
154
|
+
1. Fork 仓库
|
|
155
|
+
2. git clone <your-fork>
|
|
156
|
+
3. git remote add upstream <original>
|
|
157
|
+
4. git checkout -b feature
|
|
158
|
+
5. 开发 & 提交
|
|
159
|
+
6. git push origin feature
|
|
160
|
+
7. 创建 PR
|
|
161
|
+
|
|
162
|
+
# 同步上游
|
|
163
|
+
git fetch upstream
|
|
164
|
+
git rebase upstream/main
|
|
165
|
+
git push origin main
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## 安全规范
|
|
169
|
+
|
|
170
|
+
```yaml
|
|
171
|
+
禁止:
|
|
172
|
+
- git push --force (除非明确要求)
|
|
173
|
+
- git reset --hard (除非明确要求)
|
|
174
|
+
- git clean -f
|
|
175
|
+
|
|
176
|
+
必须:
|
|
177
|
+
- commit 前 git status 确认
|
|
178
|
+
- 使用具体文件名 add
|
|
179
|
+
- 每次 commit 聚焦单一变更
|
|
180
|
+
```
|
|
181
|
+
|