@zjex/git-workflow 0.2.24 → 0.3.0

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.
Files changed (92) hide show
  1. package/.github/workflows/deploy-docs.yml +68 -0
  2. package/.github/workflows/test.yml +24 -4
  3. package/.husky/pre-commit +14 -0
  4. package/README.md +72 -1066
  5. package/dist/index.js +103 -13
  6. package/docs/.vitepress/cache/deps/_metadata.json +52 -0
  7. package/docs/.vitepress/cache/deps/chunk-2CLQ7TTZ.js +9719 -0
  8. package/docs/.vitepress/cache/deps/chunk-2CLQ7TTZ.js.map +7 -0
  9. package/docs/.vitepress/cache/deps/chunk-LE5NDSFD.js +12824 -0
  10. package/docs/.vitepress/cache/deps/chunk-LE5NDSFD.js.map +7 -0
  11. package/docs/.vitepress/cache/deps/package.json +3 -0
  12. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js +4505 -0
  13. package/docs/.vitepress/cache/deps/vitepress___@vue_devtools-api.js.map +7 -0
  14. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js +583 -0
  15. package/docs/.vitepress/cache/deps/vitepress___@vueuse_core.js.map +7 -0
  16. package/docs/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js +1352 -0
  17. package/docs/.vitepress/cache/deps/vitepress___@vueuse_integrations_useFocusTrap.js.map +7 -0
  18. package/docs/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js.js +1665 -0
  19. package/docs/.vitepress/cache/deps/vitepress___mark__js_src_vanilla__js.js.map +7 -0
  20. package/docs/.vitepress/cache/deps/vitepress___minisearch.js +1813 -0
  21. package/docs/.vitepress/cache/deps/vitepress___minisearch.js.map +7 -0
  22. package/docs/.vitepress/cache/deps/vue.js +347 -0
  23. package/docs/.vitepress/cache/deps/vue.js.map +7 -0
  24. package/docs/.vitepress/cache/deps_temp_44e2fb0f/chunk-2CLQ7TTZ.js +9719 -0
  25. package/docs/.vitepress/cache/deps_temp_44e2fb0f/chunk-2CLQ7TTZ.js.map +7 -0
  26. package/docs/.vitepress/cache/deps_temp_44e2fb0f/chunk-LE5NDSFD.js +12824 -0
  27. package/docs/.vitepress/cache/deps_temp_44e2fb0f/chunk-LE5NDSFD.js.map +7 -0
  28. package/docs/.vitepress/cache/deps_temp_44e2fb0f/package.json +3 -0
  29. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vue_devtools-api.js +4505 -0
  30. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vue_devtools-api.js.map +7 -0
  31. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vueuse_core.js +583 -0
  32. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vueuse_core.js.map +7 -0
  33. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vueuse_integrations_useFocusTrap.js +1352 -0
  34. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___@vueuse_integrations_useFocusTrap.js.map +7 -0
  35. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___mark__js_src_vanilla__js.js +1665 -0
  36. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___mark__js_src_vanilla__js.js.map +7 -0
  37. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___minisearch.js +1813 -0
  38. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vitepress___minisearch.js.map +7 -0
  39. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vue.js +347 -0
  40. package/docs/.vitepress/cache/deps_temp_44e2fb0f/vue.js.map +7 -0
  41. package/docs/.vitepress/config.ts +167 -0
  42. package/docs/.vitepress/theme/custom.css +39 -0
  43. package/docs/.vitepress/theme/index.ts +4 -0
  44. package/docs/README.md +82 -0
  45. package/docs/commands/branch.md +468 -0
  46. package/docs/commands/commit.md +554 -0
  47. package/docs/commands/config.md +346 -0
  48. package/docs/commands/index.md +312 -0
  49. package/docs/commands/interactive.md +384 -0
  50. package/docs/commands/release.md +300 -0
  51. package/docs/commands/stash.md +309 -0
  52. package/docs/commands/tag.md +278 -0
  53. package/docs/commands/update.md +347 -0
  54. package/docs/config/ai-config.md +160 -0
  55. package/docs/config/branch-config.md +133 -0
  56. package/docs/config/commit-config.md +185 -0
  57. package/docs/config/config-file.md +776 -0
  58. package/docs/config/examples.md +279 -0
  59. package/docs/config/index.md +478 -0
  60. package/docs/guide/ai-commit.md +576 -0
  61. package/docs/guide/basic-usage.md +522 -0
  62. package/docs/guide/best-practices.md +426 -0
  63. package/docs/guide/branch-management.md +712 -0
  64. package/docs/guide/getting-started.md +294 -0
  65. package/docs/guide/index.md +168 -0
  66. package/docs/guide/installation.md +449 -0
  67. package/docs/guide/release-management.md +744 -0
  68. package/docs/guide/stash-management.md +608 -0
  69. package/docs/guide/tag-management.md +614 -0
  70. package/docs/index.md +205 -0
  71. package/docs/public/favicon.svg +21 -0
  72. package/docs/public/hero-logo.svg +43 -0
  73. package/docs/public/logo.svg +20 -0
  74. package/package.json +11 -2
  75. package/scripts/publish.js +55 -8
  76. package/scripts/publish.sh +20 -2
  77. package/scripts/release.sh +20 -2
  78. package/scripts/update-test-count.js +55 -0
  79. package/src/ai-service.ts +101 -15
  80. package/src/commands/init.ts +18 -0
  81. package/src/config.ts +1 -0
  82. package/tests/ai-service.test.ts +237 -2
  83. package/tests/help.test.ts +134 -0
  84. package/tests/init.test.ts +582 -0
  85. package/tests/release.test.ts +333 -0
  86. package/tests/setup.ts +21 -0
  87. package/tests/stash.test.ts +376 -0
  88. package/tests/update.test.ts +402 -0
  89. package/vitest.config.ts +3 -0
  90. package/zjex-logo.svg +22 -0
  91. package/zjex-optimized.svg +34 -0
  92. package/zjex.svg +1 -0
@@ -0,0 +1,776 @@
1
+ # 配置文件详解
2
+
3
+ Git Workflow 使用 JSON 格式的配置文件来自定义工具行为,支持全局配置和项目配置两种模式。
4
+
5
+ ## 📁 配置文件位置
6
+
7
+ ### 查找顺序
8
+
9
+ Git Workflow 按以下顺序查找配置文件:
10
+
11
+ 1. **当前目录** - `./gwrc.json`
12
+ 2. **Git 仓库根目录** - `<git-root>/.gwrc.json`
13
+ 3. **用户主目录** - `~/.gwrc.json`
14
+ 4. **内置默认配置**
15
+
16
+ ### 支持的文件名
17
+
18
+ 项目配置支持多种文件名:
19
+
20
+ ```bash
21
+ .gwrc.json # 推荐,JSON 格式
22
+ .gwrc # 简化文件名
23
+ gw.config.json # 明确的配置文件名
24
+ ```
25
+
26
+ 全局配置固定为:
27
+
28
+ ```bash
29
+ ~/.gwrc.json # 用户主目录下的全局配置
30
+ ```
31
+
32
+ ## 🔧 完整配置示例
33
+
34
+ ### 基础配置
35
+
36
+ ```json
37
+ {
38
+ "baseBranch": "develop",
39
+ "featurePrefix": "feature",
40
+ "hotfixPrefix": "hotfix",
41
+ "requireId": true,
42
+ "featureIdLabel": "Story ID",
43
+ "hotfixIdLabel": "Issue ID",
44
+ "defaultTagPrefix": "v",
45
+ "autoPush": true,
46
+ "autoStage": true,
47
+ "useEmoji": true
48
+ }
49
+ ```
50
+
51
+ ### 完整配置
52
+
53
+ ```json
54
+ {
55
+ "baseBranch": "develop",
56
+ "featurePrefix": "feature",
57
+ "hotfixPrefix": "hotfix",
58
+ "requireId": true,
59
+ "featureIdLabel": "Story ID",
60
+ "hotfixIdLabel": "Issue ID",
61
+ "defaultTagPrefix": "v",
62
+ "autoPush": true,
63
+ "autoStage": true,
64
+ "useEmoji": true,
65
+ "commitEmojis": {
66
+ "feat": "✨",
67
+ "fix": "🐛",
68
+ "docs": "📝",
69
+ "style": "💄",
70
+ "refactor": "♻️",
71
+ "perf": "⚡️",
72
+ "test": "✅",
73
+ "build": "📦",
74
+ "ci": "👷",
75
+ "chore": "🔧",
76
+ "revert": "⏪"
77
+ },
78
+ "aiCommit": {
79
+ "enabled": true,
80
+ "provider": "github",
81
+ "apiKey": "",
82
+ "model": "gpt-4o-mini",
83
+ "language": "zh-CN",
84
+ "maxTokens": 200,
85
+ "detailedDescription": true,
86
+ "temperature": 0.7,
87
+ "customPrompt": ""
88
+ },
89
+ "release": {
90
+ "autoCommit": false,
91
+ "autoTag": false,
92
+ "commitMessage": "chore: release v{version}",
93
+ "tagMessage": "Release v{version}"
94
+ },
95
+ "hooks": {
96
+ "preCommit": "",
97
+ "postCommit": "",
98
+ "preTag": "",
99
+ "postTag": ""
100
+ }
101
+ }
102
+ ```
103
+
104
+ ## 📋 配置项详解
105
+
106
+ ### 分支配置
107
+
108
+ #### baseBranch
109
+
110
+ **类型:** `string`
111
+ **默认值:** 自动检测
112
+ **说明:** 默认基础分支,不设置则自动检测 main/master
113
+
114
+ ```json
115
+ {
116
+ "baseBranch": "develop"
117
+ }
118
+ ```
119
+
120
+ **效果:**
121
+ - 所有新分支都基于 `develop` 创建
122
+ - 除非使用 `--base` 参数覆盖
123
+
124
+ #### featurePrefix
125
+
126
+ **类型:** `string`
127
+ **默认值:** `"feature"`
128
+ **说明:** feature 分支前缀
129
+
130
+ ```json
131
+ {
132
+ "featurePrefix": "feat"
133
+ }
134
+ ```
135
+
136
+ **效果:**
137
+ - 生成分支名:`feat/20260111-PROJ-123-add-login`
138
+
139
+ #### hotfixPrefix
140
+
141
+ **类型:** `string`
142
+ **默认值:** `"hotfix"`
143
+ **说明:** hotfix 分支前缀
144
+
145
+ ```json
146
+ {
147
+ "hotfixPrefix": "fix"
148
+ }
149
+ ```
150
+
151
+ **效果:**
152
+ - 生成分支名:`fix/20260111-BUG-456-fix-crash`
153
+
154
+ #### requireId
155
+
156
+ **类型:** `boolean`
157
+ **默认值:** `false`
158
+ **说明:** 是否强制要求填写 ID
159
+
160
+ ```json
161
+ {
162
+ "requireId": true
163
+ }
164
+ ```
165
+
166
+ **效果:**
167
+ - 创建分支时必须填写 ID,不能跳过
168
+ - 确保每个分支都能追溯到具体需求
169
+
170
+ #### featureIdLabel
171
+
172
+ **类型:** `string`
173
+ **默认值:** `"Story ID"`
174
+ **说明:** feature 分支 ID 提示文字
175
+
176
+ ```json
177
+ {
178
+ "featureIdLabel": "Jira ID"
179
+ }
180
+ ```
181
+
182
+ **效果:**
183
+ - 提示文字变为:"请输入 Jira ID (可跳过):"
184
+
185
+ #### hotfixIdLabel
186
+
187
+ **类型:** `string`
188
+ **默认值:** `"Issue ID"`
189
+ **说明:** hotfix 分支 ID 提示文字
190
+
191
+ ```json
192
+ {
193
+ "hotfixIdLabel": "Bug ID"
194
+ }
195
+ ```
196
+
197
+ **效果:**
198
+ - 提示文字变为:"请输入 Bug ID (可跳过):"
199
+
200
+ #### autoPush
201
+
202
+ **类型:** `boolean`
203
+ **默认值:** 不设置(每次询问)
204
+ **说明:** 创建分支后是否自动推送到远程
205
+
206
+ ```json
207
+ {
208
+ "autoPush": true
209
+ }
210
+ ```
211
+
212
+ **选项说明:**
213
+ - `true` - 自动推送,不询问
214
+ - `false` - 不推送,不询问
215
+ - 不设置 - 每次询问(默认行为)
216
+
217
+ ### 版本配置
218
+
219
+ #### defaultTagPrefix
220
+
221
+ **类型:** `string`
222
+ **默认值:** 不设置
223
+ **说明:** 默认 tag 前缀,设置后跳过选择步骤
224
+
225
+ ```json
226
+ {
227
+ "defaultTagPrefix": "v"
228
+ }
229
+ ```
230
+
231
+ **效果:**
232
+ - 创建 tag 时直接使用 `v` 前缀
233
+ - 跳过前缀选择界面
234
+
235
+ ### 提交配置
236
+
237
+ #### autoStage
238
+
239
+ **类型:** `boolean`
240
+ **默认值:** `true`
241
+ **说明:** commit 时是否自动暂存所有更改
242
+
243
+ ```json
244
+ {
245
+ "autoStage": false
246
+ }
247
+ ```
248
+
249
+ **效果:**
250
+ - `true` - 自动暂存所有更改
251
+ - `false` - 手动选择要暂存的文件
252
+
253
+ #### useEmoji
254
+
255
+ **类型:** `boolean`
256
+ **默认值:** `true`
257
+ **说明:** commit 时是否使用 emoji
258
+
259
+ ```json
260
+ {
261
+ "useEmoji": false
262
+ }
263
+ ```
264
+
265
+ **效果:**
266
+ - `true` - `✨ feat(auth): 添加登录功能`
267
+ - `false` - `feat(auth): 添加登录功能`
268
+
269
+ #### commitEmojis
270
+
271
+ **类型:** `object`
272
+ **默认值:** 内置 emoji 映射
273
+ **说明:** 自定义各类型 commit 的 emoji
274
+
275
+ ```json
276
+ {
277
+ "commitEmojis": {
278
+ "feat": "🎉",
279
+ "fix": "🔧",
280
+ "docs": "📚"
281
+ }
282
+ }
283
+ ```
284
+
285
+ **效果:**
286
+ - 只覆盖指定的类型
287
+ - 未指定的类型使用默认 emoji
288
+
289
+ ### AI 配置
290
+
291
+ #### aiCommit.enabled
292
+
293
+ **类型:** `boolean`
294
+ **默认值:** `true`
295
+ **说明:** 是否启用 AI commit 功能
296
+
297
+ ```json
298
+ {
299
+ "aiCommit": {
300
+ "enabled": false
301
+ }
302
+ }
303
+ ```
304
+
305
+ #### aiCommit.provider
306
+
307
+ **类型:** `string`
308
+ **默认值:** `"github"`
309
+ **说明:** AI 提供商
310
+
311
+ ```json
312
+ {
313
+ "aiCommit": {
314
+ "provider": "openai"
315
+ }
316
+ }
317
+ ```
318
+
319
+ **支持的提供商:**
320
+ - `github` - GitHub Models
321
+ - `openai` - OpenAI
322
+ - `claude` - Anthropic Claude
323
+ - `ollama` - 本地 Ollama
324
+
325
+ #### aiCommit.apiKey
326
+
327
+ **类型:** `string`
328
+ **默认值:** 空字符串
329
+ **说明:** API key,留空使用内置 key(仅 GitHub Models)
330
+
331
+ ```json
332
+ {
333
+ "aiCommit": {
334
+ "apiKey": "your-api-key-here"
335
+ }
336
+ }
337
+ ```
338
+
339
+ #### aiCommit.model
340
+
341
+ **类型:** `string`
342
+ **默认值:** 根据提供商
343
+ **说明:** 模型名称
344
+
345
+ ```json
346
+ {
347
+ "aiCommit": {
348
+ "provider": "openai",
349
+ "model": "gpt-4o-mini"
350
+ }
351
+ }
352
+ ```
353
+
354
+ **常用模型:**
355
+ - GitHub: `gpt-4o-mini`, `gpt-4o`
356
+ - OpenAI: `gpt-4o-mini`, `gpt-3.5-turbo`
357
+ - Claude: `claude-3-haiku-20240307`
358
+ - Ollama: `llama3.2:3b`, `qwen2.5:7b`
359
+
360
+ #### aiCommit.language
361
+
362
+ **类型:** `string`
363
+ **默认值:** `"zh-CN"`
364
+ **说明:** 生成语言
365
+
366
+ ```json
367
+ {
368
+ "aiCommit": {
369
+ "language": "en-US"
370
+ }
371
+ }
372
+ ```
373
+
374
+ **支持的语言:**
375
+ - `zh-CN` - 中文
376
+ - `en-US` - 英文
377
+
378
+ #### aiCommit.maxTokens
379
+
380
+ **类型:** `number`
381
+ **默认值:** `200`(简洁模式)/ `400`(详细模式)
382
+ **说明:** 最大 token 数
383
+
384
+ ```json
385
+ {
386
+ "aiCommit": {
387
+ "maxTokens": 150
388
+ }
389
+ }
390
+ ```
391
+
392
+ #### aiCommit.detailedDescription
393
+
394
+ **类型:** `boolean`
395
+ **默认值:** `true`
396
+ **说明:** 是否生成详细的修改点描述
397
+
398
+ ```json
399
+ {
400
+ "aiCommit": {
401
+ "detailedDescription": true
402
+ }
403
+ }
404
+ ```
405
+
406
+ **效果对比:**
407
+
408
+ 简洁模式(`detailedDescription: false`):
409
+ ```
410
+ feat(auth): 添加用户登录功能
411
+ ```
412
+
413
+ 详细模式(`detailedDescription: true`):
414
+ ```
415
+ feat(auth): 添加用户登录功能
416
+
417
+ - 实现用户名密码登录接口
418
+ - 添加登录状态验证中间件
419
+ - 完善登录错误处理逻辑
420
+ - 更新用户认证相关文档
421
+ ```
422
+
423
+ **注意:** 详细模式会自动使用更大的 `maxTokens`(400)和更长的 diff 长度限制(6000 字符)。
424
+
425
+ #### aiCommit.temperature
426
+
427
+ **类型:** `number`
428
+ **默认值:** `0.7`
429
+ **说明:** 创造性参数(0-1)
430
+
431
+ ```json
432
+ {
433
+ "aiCommit": {
434
+ "temperature": 0.3
435
+ }
436
+ }
437
+ ```
438
+
439
+ **参数说明:**
440
+ - `0.0-0.3` - 保守,结果一致性高
441
+ - `0.4-0.7` - 平衡(推荐)
442
+ - `0.8-1.0` - 创造性高,结果多样
443
+
444
+ #### aiCommit.customPrompt
445
+
446
+ **类型:** `string`
447
+ **默认值:** 空字符串
448
+ **说明:** 自定义提示词
449
+
450
+ ```json
451
+ {
452
+ "aiCommit": {
453
+ "customPrompt": "请生成简洁的中文 commit message,格式为:类型(范围): 描述"
454
+ }
455
+ }
456
+ ```
457
+
458
+ ### 发布配置
459
+
460
+ #### release.autoCommit
461
+
462
+ **类型:** `boolean`
463
+ **默认值:** `false`
464
+ **说明:** 版本更新后是否自动提交
465
+
466
+ ```json
467
+ {
468
+ "release": {
469
+ "autoCommit": true
470
+ }
471
+ }
472
+ ```
473
+
474
+ #### release.autoTag
475
+
476
+ **类型:** `boolean`
477
+ **默认值:** `false`
478
+ **说明:** 版本更新后是否自动创建标签
479
+
480
+ ```json
481
+ {
482
+ "release": {
483
+ "autoTag": true
484
+ }
485
+ }
486
+ ```
487
+
488
+ #### release.commitMessage
489
+
490
+ **类型:** `string`
491
+ **默认值:** `"chore: release v{version}"`
492
+ **说明:** 版本提交的消息模板
493
+
494
+ ```json
495
+ {
496
+ "release": {
497
+ "commitMessage": "🔖 chore: 发布版本 v{version}"
498
+ }
499
+ }
500
+ ```
501
+
502
+ #### release.tagMessage
503
+
504
+ **类型:** `string`
505
+ **默认值:** `"Release v{version}"`
506
+ **说明:** 标签消息模板
507
+
508
+ ```json
509
+ {
510
+ "release": {
511
+ "tagMessage": "发布版本 v{version}"
512
+ }
513
+ }
514
+ ```
515
+
516
+ ### 钩子配置
517
+
518
+ #### hooks.preCommit
519
+
520
+ **类型:** `string`
521
+ **默认值:** 空字符串
522
+ **说明:** 提交前执行的命令
523
+
524
+ ```json
525
+ {
526
+ "hooks": {
527
+ "preCommit": "npm run lint"
528
+ }
529
+ }
530
+ ```
531
+
532
+ #### hooks.postCommit
533
+
534
+ **类型:** `string`
535
+ **默认值:** 空字符串
536
+ **说明:** 提交后执行的命令
537
+
538
+ ```json
539
+ {
540
+ "hooks": {
541
+ "postCommit": "npm run build"
542
+ }
543
+ }
544
+ ```
545
+
546
+ #### hooks.preTag
547
+
548
+ **类型:** `string`
549
+ **默认值:** 空字符串
550
+ **说明:** 创建标签前执行的命令
551
+
552
+ ```json
553
+ {
554
+ "hooks": {
555
+ "preTag": "npm test"
556
+ }
557
+ }
558
+ ```
559
+
560
+ #### hooks.postTag
561
+
562
+ **类型:** `string`
563
+ **默认值:** 空字符串
564
+ **说明:** 创建标签后执行的命令
565
+
566
+ ```json
567
+ {
568
+ "hooks": {
569
+ "postTag": "npm run changelog"
570
+ }
571
+ }
572
+ ```
573
+
574
+ ## 🎯 配置场景示例
575
+
576
+ ### 个人开发者配置
577
+
578
+ ```json
579
+ {
580
+ "autoStage": true,
581
+ "useEmoji": true,
582
+ "requireId": false,
583
+ "aiCommit": {
584
+ "enabled": true,
585
+ "provider": "github",
586
+ "language": "zh-CN"
587
+ }
588
+ }
589
+ ```
590
+
591
+ ### 团队协作配置
592
+
593
+ ```json
594
+ {
595
+ "baseBranch": "develop",
596
+ "requireId": true,
597
+ "featureIdLabel": "Jira ID",
598
+ "hotfixIdLabel": "Bug ID",
599
+ "autoPush": true,
600
+ "useEmoji": false,
601
+ "autoStage": false
602
+ }
603
+ ```
604
+
605
+ ### 企业级配置
606
+
607
+ ```json
608
+ {
609
+ "featurePrefix": "feat",
610
+ "hotfixPrefix": "fix",
611
+ "requireId": true,
612
+ "featureIdLabel": "需求编号",
613
+ "hotfixIdLabel": "缺陷编号",
614
+ "useEmoji": false,
615
+ "autoStage": false,
616
+ "aiCommit": {
617
+ "enabled": false
618
+ },
619
+ "hooks": {
620
+ "preCommit": "npm run lint && npm test",
621
+ "preTag": "npm run build"
622
+ }
623
+ }
624
+ ```
625
+
626
+ ### 开源项目配置
627
+
628
+ ```json
629
+ {
630
+ "baseBranch": "main",
631
+ "requireId": false,
632
+ "useEmoji": true,
633
+ "aiCommit": {
634
+ "enabled": true,
635
+ "language": "en-US"
636
+ },
637
+ "release": {
638
+ "autoCommit": true,
639
+ "commitMessage": "chore: release v{version}"
640
+ }
641
+ }
642
+ ```
643
+
644
+ ## 🔧 配置管理
645
+
646
+ ### 创建配置文件
647
+
648
+ ```bash
649
+ # 交互式创建
650
+ gw init
651
+
652
+ # 手动创建
653
+ touch .gwrc.json
654
+ ```
655
+
656
+ ### 验证配置文件
657
+
658
+ ```bash
659
+ # 检查配置语法
660
+ node -e "console.log(JSON.parse(require('fs').readFileSync('.gwrc.json', 'utf8')))"
661
+
662
+ # 或使用在线 JSON 验证工具
663
+ ```
664
+
665
+ ### 配置文件模板
666
+
667
+ ```bash
668
+ # 复制配置模板
669
+ cp ~/.gwrc.json .gwrc.json
670
+
671
+ # 或从其他项目复制
672
+ cp ../other-project/.gwrc.json .
673
+ ```
674
+
675
+ ### 配置合并规则
676
+
677
+ 当存在多个配置文件时,Git Workflow 会按优先级合并:
678
+
679
+ 1. **项目配置** 覆盖 **全局配置**
680
+ 2. **全局配置** 覆盖 **默认配置**
681
+ 3. **对象类型** 进行深度合并
682
+ 4. **基本类型** 直接覆盖
683
+
684
+ **示例:**
685
+
686
+ 全局配置:
687
+ ```json
688
+ {
689
+ "useEmoji": true,
690
+ "aiCommit": {
691
+ "enabled": true,
692
+ "provider": "github",
693
+ "language": "zh-CN"
694
+ }
695
+ }
696
+ ```
697
+
698
+ 项目配置:
699
+ ```json
700
+ {
701
+ "requireId": true,
702
+ "aiCommit": {
703
+ "provider": "openai"
704
+ }
705
+ }
706
+ ```
707
+
708
+ 最终生效配置:
709
+ ```json
710
+ {
711
+ "useEmoji": true,
712
+ "requireId": true,
713
+ "aiCommit": {
714
+ "enabled": true,
715
+ "provider": "openai",
716
+ "language": "zh-CN"
717
+ }
718
+ }
719
+ ```
720
+
721
+ ## 🚨 常见问题
722
+
723
+ ### 配置文件语法错误
724
+
725
+ ```bash
726
+ ❌ 配置文件语法错误: Unexpected token } in JSON
727
+ ```
728
+
729
+ **解决方案:**
730
+ 1. 使用 JSON 验证工具检查语法
731
+ 2. 检查是否有多余的逗号
732
+ 3. 确保字符串使用双引号
733
+
734
+ ### 配置项不生效
735
+
736
+ ```bash
737
+ ❌ 配置项 'unknownOption' 不被识别
738
+ ```
739
+
740
+ **解决方案:**
741
+ 1. 检查配置项名称是否正确
742
+ 2. 查看文档确认支持的配置项
743
+ 3. 更新到最新版本
744
+
745
+ ### 权限问题
746
+
747
+ ```bash
748
+ ❌ 无法写入配置文件: Permission denied
749
+ ```
750
+
751
+ **解决方案:**
752
+ 1. 检查文件权限:`ls -la .gwrc.json`
753
+ 2. 修改权限:`chmod 644 .gwrc.json`
754
+ 3. 检查目录权限
755
+
756
+ ### 配置冲突
757
+
758
+ ```bash
759
+ ⚠️ 项目配置与全局配置存在冲突
760
+ ```
761
+
762
+ **解决方案:**
763
+ 1. 项目配置优先级更高
764
+ 2. 检查合并结果是否符合预期
765
+ 3. 根据需要调整配置
766
+
767
+ ## 📚 相关文档
768
+
769
+ - [**AI 配置**](/config/ai-config) - 详细的 AI commit 配置
770
+ - [**分支配置**](/config/branch-config) - 分支管理相关配置
771
+ - [**提交配置**](/config/commit-config) - 提交相关配置
772
+ - [**配置示例**](/config/examples) - 更多实际配置案例
773
+
774
+ ---
775
+
776
+ 通过合理配置,Git Workflow 可以完美适应你的工作流程。配置文件是工具的核心,掌握配置文件的使用是高效使用 Git Workflow 的关键。