@@ -67,31 +67,6 @@ curl -sS https://201.ustclug.org/assets/gitconfig_sample >> ~/.gitconfig
67
67
68
68
GitHub 在 [ 这里] ( https://github.com/github/gitignore ) 提供了一些常见的 ` .gitignore ` 文件,对于较为复杂的项目,也可以使用[ gitignore.io] ( https://www.gitignore.io/ ) 生成。
69
69
70
- !!! warning "` .env ` 文件与 ` .gitignore ` "
71
-
72
- 有些项目在开发的途中,可能引入 `.env` 用于存放测试环境的配置,这类文件通常包含敏感信息,因此应该被加入到 `.gitignore` 中。
73
-
74
- 值得注意的是, `.gitignore` 文件本身也会进行版本管理, 这意味着, 当使用 `git reset` 回退版本时, `.gitignore` 也会被回退, 这可能会导致 `.env` 文件重新被 `git` 管理, 在马虎的操作下 (如 `git commit -a`), `.env` 文件可能会被提交到版本库中。
75
-
76
- ```mermaid
77
- classDiagram
78
- direction LR
79
- CommitA --|> CommitB : "Add .env to .gitignore"
80
- CommitB --|> CommitA_revert : reset --hard
81
- CommitA: .gitignore (without .env)
82
- CommitB: .gitignore (including .env)
83
- CommitB: .env
84
- CommitA_revert: .env (untracked)
85
- CommitA_revert: .gitignore (without .env)
86
- ```
87
-
88
- 此时可以考虑:
89
-
90
- - 将 `.env` 移除版本控制,例如 `mv ./.env ../.env.bk`
91
- - 将 `.env` 添加到 `.git/info/exclude` 或 `~/.gitignore_global` 中,
92
-
93
- 以防止`.env`被提交。
94
-
95
70
!!! note "仅本地的 gitignore"
96
71
97
72
本地的 `.git/info/exclude` 起到与 `.gitignore` 相同的作用,但是不会被提交到版本库中,适用于以下的情况:
@@ -220,7 +195,7 @@ git bisect bad <new-commit>
220
195
- `body` 是 commit 的详细描述,通常会引用 issue、解释修改的原因等
221
196
- `footer` 通常用于引用 issue、关闭 issue 等,例如 `Closes #123`,也可以用于指定 breaking change 等
222
197
223
- 值得注意的是,以上规范仅仅只是推荐,实际使用时可以根据项目的实际情况进行调整,例如本文档所存放的[仓库](https://github.com/ustclug/Linux201-docs)是一个文档类的项目,一般情况下可以直接省略掉`type`.
198
+ 值得注意的是,以上规范仅仅只是推荐,实际使用时可以根据项目的实际情况进行调整,例如本文档所存放的[仓库](https://github.com/ustclug/Linux201-docs)是一个文档类的项目,一般情况下可以直接省略掉`type`, 可用文档相对目录来替代,例如修改本文的 Commit Message 一般就写成 `dev/git: fix typo` .
224
199
225
200
!!! note "Commit Message 模板"
226
201
@@ -248,17 +223,59 @@ git commit -a -m "fix: some bug"
248
223
gh pr create
249
224
```
250
225
226
+ 其他常用的 GitHub CLI 命令包括:
227
+
228
+ - ` gh repo view --web ` :在浏览器中打开当前仓库
229
+ - ` gh issue list ` :列出当前仓库的 Issue
230
+ - ` gh run watch ` :查看当前仓库的 GitHub Actions 运行状态
231
+
232
+ ??? note "` gh run watch ` "
233
+
234
+ 默认情况下 `gh run watch` 需要手动选择关注的 GitHub workflow, 如果只想关注最新的 workflow 可以将如下函数添加到 `~/.bashrc` 或 `~/.zshrc`:
235
+
236
+ ```bash
237
+ watch_latest_run() {
238
+ # Fetch the latest run ID using gh and jq
239
+ local latest_run_id=$(gh run list --limit 1 --json databaseId --jq '.[0].databaseId')
240
+
241
+ if [ -z "$latest_run_id" ]; then
242
+ echo "No runs found."
243
+ return 1
244
+ fi
245
+
246
+ # Pass the latest run ID to gh run watch
247
+ gh run watch "$latest_run_id"
248
+ }
249
+ ```
250
+
251
+ 之后可以直接使用 `watch_latest_run` 命令即可。
252
+
251
253
### GPG 签名 {#github-gpg}
252
254
253
255
SSH Key 只用来验证 push 环节的身份,而 GPG Key 则用来验证 Commit 的真实性。
254
256
255
257
GitHub 对 GPG Key 的文档描述很详细,我们将其列在这里:
256
258
257
259
- [ 生成 GPG Key] ( https://docs.github.com/en/authentication/managing-commit-signature-verification/generating-a-new-gpg-key )
258
- - [ 修改 GPG Key 信息] ( https://docs.github.com/en/authentication/managing-commit-signature-verification/associating-an-email-with-your-gpg-key )
260
+ - [ 修改 GPG Key 信息] ( https://docs.github.com/en/authentication/managing-commit-signature-verification/associating-an-email-with-your-gpg-key )
259
261
- [ 设置 Git 使用 GPG Sign] ( https://docs.github.com/en/authentication/managing-commit-signature-verification/telling-git-about-your-signing-key )
260
262
- [ 在 GitHub 上关联 GPG Key] ( https://docs.github.com/en/authentication/managing-commit-signature-verification/adding-a-gpg-key-to-your-github-account )
261
263
264
+ 请注意备份 GPG Key, 并额外向其他 Key Server 发布 GPG Key, 以防止 GPG Key 丢失:
265
+
266
+ ``` bash
267
+ gpg --list-secret-keys --keyid-format LONG
268
+ gpg --armor --export < GPG Key ID> | tee gpg.key
269
+ gpg --keyserver keyserver.ubuntu.com --send-keys < GPG Key ID>
270
+ gpg --keyserver pgp.mit.edu --send-keys < GPG Key ID>
271
+ ```
272
+
273
+ !!! warning "过期的 GPG Key"
274
+
275
+ 过期的 GPG Key 是可以更新的, 参考 [这个 StackOverflow 回答](https://superuser.com/a/1141251).
276
+ 在 GitHub 上 rotate 只需要删除旧的 GPG Key, 然后重新添加新的 GPG Key 即可.
277
+ 值得注意的是过期的 GPG Key 签名的 commit 依然会显示成 Verified, 因此**不要轻易删除过期的 GPG Key**.
278
+
262
279
### Issue {#github-issue}
263
280
264
281
下面关于 Markdown 的特性并不限于 Issue,也适用于 Pull Request 等。
@@ -269,13 +286,14 @@ GitHub 对 GPG Key 的文档描述很详细,我们将其列在这里:
269
286
270
287
- 在 Issue 中,可以使用 ` # ` 来引用其他 Issue / PR,例如 ` #133 `
271
288
- 可以通过 ` user/repo#issue_number ` 的方式引用其他仓库的 Issue / PR,例如 ` tuna/issues#341 `
289
+
272
290
- 当一个 PR 包含如下关键字,并且按照上述方法连接到一个 Issue 时,合并这个 PR 会关闭对应的 issue:
273
291
274
- ```txt
275
- close(s,d) #123
276
- fix(es, ed) #123
277
- resolve(s, d) #123
278
- ```
292
+ ``` txt
293
+ close(s,d) #123
294
+ fix(es, ed) #123
295
+ resolve(s, d) #123
296
+ ```
279
297
280
298
- 可以通过 GitHub Web 上 Copy permalink 的方式获取代码的链接,例如打开 [ustclug/mirrorrequest/README.md](https://github.com/ustclug/mirrorrequest/blob/master/README.md?plain=1) 后,可以选择某一行,点击左侧的菜单,选择 Copy permalink, 即可获得诸如 <https://github.com/ustclug/mirrorrequest/blob/f23dd1f1cbe81f01e4f878ac11ee064b6c7d70ec/README.md?plain=1#L1> 这样的链接。
281
299
- 这样的链接可以在 Issue 中直接粘贴,会被以代码框的形式渲染到 Issue 中,方便其他人迅速了解问题。
@@ -289,40 +307,40 @@ GitHub 对 GPG Key 的文档描述很详细,我们将其列在这里:
289
307
290
308
- [Mermaid 关系图](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/creating-diagrams)
291
309
292
- Mermaid 是一种简单且强大的关系图/流程图语法,例如可以通过如下方式创建一个简单的关系图:
293
-
294
- ```` txt
295
- ```mermaid
296
- graph LR;
297
- A-->B;
298
- A-->C;
299
- B-->D;
300
- C-->D;
301
- ```
302
- ````
303
-
304
- ```mermaid
305
- graph LR;
306
- A-->B;
307
- A-->C;
308
- B-->D;
309
- C-->D;
310
- ```
310
+ Mermaid 是一种简单且强大的关系图/流程图语法,例如可以通过如下方式创建一个简单的关系图:
311
+
312
+ ````txt
313
+ ```mermaid
314
+ graph LR;
315
+ A-->B;
316
+ A-->C;
317
+ B-->D;
318
+ C-->D;
319
+ ```
320
+ ````
321
+
322
+ ```mermaid
323
+ graph LR;
324
+ A-->B;
325
+ A-->C;
326
+ B-->D;
327
+ C-->D;
328
+ ```
311
329
312
330
- [MathJax 支持](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/writing-mathematical-expressions)
313
331
314
- GitHub 通过 MathJax 支持 LaTeX 公式,可以通过 `$ \frac 12 $` 的形式创建行内公式, `$$ \frac 12 $$` 的形式创建块级公式。
332
+ GitHub 通过 MathJax 支持 LaTeX 公式,可以通过 `$ \frac 12 $` 的形式创建行内公式, `$$ \frac 12 $$` 的形式创建块级公式。
315
333
316
334
- [进度跟踪](https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/about-task-lists)
317
335
318
- 在 Issue 正文中创建一个任务列表,例如:
336
+ 在 Issue 正文中创建一个任务列表,例如:
319
337
320
- ```markdown
321
- - [x] Task 1 #123
322
- - [ ] Task 2
323
- ```
338
+ ```markdown
339
+ - [x] Task 1 #123
340
+ - [ ] Task 2
341
+ ```
324
342
325
- 此时可以将这个 Issue 转化为一个任务列表,方便追踪任务的进度,同时 `#123` 会被标记为 `Tracked by #xxx`。
343
+ 此时可以将这个 Issue 转化为一个任务列表,方便追踪任务的进度,同时 `#123` 会被标记为 `Tracked by #xxx`。
326
344
327
345
#### Issue 模板 {#github-issue-template}
328
346
@@ -332,16 +350,16 @@ GitHub 对 GPG Key 的文档描述很详细,我们将其列在这里:
332
350
name: Bug Report
333
351
about: Create a report to help us improve
334
352
labels:
335
- - bug
353
+ - bug
336
354
body:
337
- - type: textarea
338
- id: bug-description
339
- attributes:
340
- label: Describe the bug
341
- description: A clear and concise description of what the bug is.
342
- placeholder: I'm always frustrated when...
343
- validations:
344
- required: true
355
+ - type: textarea
356
+ id: bug-description
357
+ attributes:
358
+ label: Describe the bug
359
+ description: A clear and concise description of what the bug is.
360
+ placeholder: I'm always frustrated when...
361
+ validations:
362
+ required: true
345
363
```
346
364
347
365
可以参考 [ustclug/mirrorrequest/.../01-mirror-request.yml](https://github.com/ustclug/mirrorrequest/blob/master/.github/ISSUE_TEMPLATE/01-mirror-request.yml?plain=1), [GitHub 文档](https://docs.github.com/en/communities/using-templates-to-encourage-useful-issues-and-pull-requests/configuring-issue-templates-for-your-repository).
0 commit comments