Skip to content

Commit b333ab1

Browse files
committed
gitignore whitelist post
1 parent c418927 commit b333ab1

File tree

12 files changed

+1066
-1809
lines changed

12 files changed

+1066
-1809
lines changed

content/posts/gitignore.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
+++
2+
date = '2025-08-08T10:00:00+08:00'
3+
draft = false
4+
title = 'Git Whitelist'
5+
+++
6+
7+
有时你开启了一个新的项目, 运行了 `cargo init``uv init``go mod init`
8+
9+
这些命令创建了工作所需要的必要文件, 同时也在 `.gitignore` 文件中添加了一下内容
10+
```
11+
target
12+
__pycache__
13+
bin
14+
```
15+
一切都很顺利, 你继续开发新功能, 等到时机成熟时就将项目发布到了 Git 托管平台上
16+
17+
人们开始对你的项目感兴趣, 甚至有人决定为你实现一个新功能, 这简直是免费劳动力!
18+
19+
当你查看代码, 发现了一个格格不入的文件 `.DS_Store`, 你问那个人这是什么, 他说他根本不知道
20+
21+
然后你只是将该文件从分支里面删除, 并把文件名加入了仓库的 `.gitignore`
22+
23+
```
24+
target
25+
__pycache__
26+
bin
27+
.DS_Store
28+
```
29+
现在代码合并到了 `main`, 仓库里只包含有用的内容
30+
31+
接着, 另一人使用基于 Web 技术的 IDE 提交了另一个合并请求, 一看发现有一个完全无关的目录也被提交了, 于是 `.gitignore` 里又增加了一条内容
32+
```
33+
target
34+
__pycache__
35+
bin
36+
.DS_Store
37+
.vscode
38+
```
39+
接下来, 有人使用 IntelliJ IDEA 提交了五百个 XML 文件和 .idea 目录, 这时又不得不将其加入 `.gitignore`
40+
```
41+
target
42+
__pycache__
43+
bin
44+
.DS_Store
45+
.vscode
46+
.idea
47+
```
48+
多年后, `.gitignore` 已经有了上百行, 但是仍然是不是有各种奇怪的文件, 例如 `testscripts``foo``a``qux``data.tar.gz``start.sh``cat` ......
49+
50+
你就像西西弗斯一样, 因欺骗死亡和冥界而受到永无止境的惩罚
51+
52+
> 西西弗斯推着一块写着 `.DS_Store` 的巨石艰难上山
53+
54+
如何改变偷偷溜进来的文件循环呢? 去教育每一个提交合并请求的人肯定不行, 得通过自动化工具结局, 而不是主观沟通
55+
56+
幸运的是, 可以将这个黑名单变成白名单, 可以通过默认忽略所有文件, 然后只手动“取消忽略”明确允许的文件
57+
```
58+
*
59+
60+
!.gitignore
61+
62+
# 白名单:任意位置下的 src 目录及其子文件夹
63+
!src/
64+
!src/**/
65+
!src/**/*.rs
66+
!Cargo.{toml,lock}
67+
68+
# 白名单:项目根目录下的 pysrc 目录
69+
!/pysrc/
70+
!/pysrc/*.py
71+
!pyproject.toml
72+
!uv.lock
73+
74+
!/cmd/
75+
!/cmd/*.go
76+
!main.go
77+
!go.{mod,sum}
78+
79+
!/docs/
80+
!/docs/*.md
81+
```
82+
现在, 没人再能不小心提交不该提交的文件了. Git 会自动忽略所有文件, 只允许那些明确列入白名单的文件.
83+
84+
这种做法也具备一定的“面向未来”的能力——当然, 前提是以后不会有某个 IDE 把 `src/ide.rs` 当成保存项目配置的理想文件路径, 但愿那一天永远不会到来...

public/archives/index.html

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,13 @@
5151
<span class="max-w-[4rem] md:max-w-none truncate">Home</span></a></li><li class="flex items-center gap-1 md:gap-2 min-w-0"><span class="text-muted-foreground/50 flex-shrink-0"><svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 5l7 7-7 7"/></svg>
5252
</span><span class="text-foreground flex items-center gap-0.5 md:gap-1 font-medium min-w-0 flex-shrink-0"><svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 8h14M5 8a2 2 0 110-4h14a2 2 0 110 4M5 8v10a2 2 0 002 2h10a2 2 0 002-2V8m-9 4h4"/></svg>
5353
<span class="max-w-[3rem] md:max-w-none truncate">Archives</span></span></li></ol></nav><header class=mb-8><div class="mb-4 flex items-center gap-3"><svg class="h-6 w-6" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 8h14M5 8a2 2 0 110-4h14a2 2 0 110 4M5 8v10a2 2 0 002 2h10a2 2 0 002-2V8m-9 4h4"/></svg><h1 class="text-foreground text-3xl font-bold">Archives</h1></div><p class="text-muted-foreground mb-6">Browse all articles in chronological order and discover what interests you.</p><div class="text-muted-foreground flex items-center gap-4 text-sm"><div class="flex items-center gap-1"><svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"/></svg>
54-
<span>6 posts total</span></div><div class="flex items-center gap-1"><svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5A2 2 0 003 7v12a2 2 0 002 2z"/></svg>
55-
<span>Timeline view</span></div></div></header><div class=relative><div class="bg-border absolute top-0 bottom-0 left-4 w-0.5"></div><div class=mb-12><div class="relative mb-8 flex items-center"><div class="bg-primary absolute left-0 z-10 flex h-8 w-8 items-center justify-center rounded-full"><svg class="h-4 w-4 text-primary-foreground" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5A2 2 0 003 7v12a2 2 0 002 2z"/></svg></div><div class=ml-12><h2 class="text-foreground text-2xl font-bold">2025</h2><p class="text-muted-foreground text-sm">6
56-
posts</p></div></div><div class="relative mb-8"><div class="relative mb-4 flex items-center"><div class="bg-accent border-background absolute left-2 z-10 h-4 w-4 rounded-full border-2"></div><div class=ml-12><h3 class="text-foreground text-lg font-semibold">August 2025</h3><p class="text-muted-foreground text-xs">6
57-
posts</p></div></div><div class="ml-12 space-y-3"><article class="group bg-card border-border hover:bg-accent/50 rounded-lg border p-4 transition-all duration-300"><div class="flex items-center justify-between gap-4"><div class="min-w-0 flex-1"><h4 class="text-foreground group-hover:text-primary mb-3 font-medium transition-colors duration-200"><a href=/posts/fastapi-parameters-and-validations/ class=block>FastAPI Parameters and Validations</a></h4><div class="text-muted-foreground flex items-center gap-4 text-xs"><div class="flex items-center gap-1"><svg class="h-3 w-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5A2 2 0 003 7v12a2 2 0 002 2z"/></svg>
54+
<span>7 posts total</span></div><div class="flex items-center gap-1"><svg class="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5A2 2 0 003 7v12a2 2 0 002 2z"/></svg>
55+
<span>Timeline view</span></div></div></header><div class=relative><div class="bg-border absolute top-0 bottom-0 left-4 w-0.5"></div><div class=mb-12><div class="relative mb-8 flex items-center"><div class="bg-primary absolute left-0 z-10 flex h-8 w-8 items-center justify-center rounded-full"><svg class="h-4 w-4 text-primary-foreground" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5A2 2 0 003 7v12a2 2 0 002 2z"/></svg></div><div class=ml-12><h2 class="text-foreground text-2xl font-bold">2025</h2><p class="text-muted-foreground text-sm">7
56+
posts</p></div></div><div class="relative mb-8"><div class="relative mb-4 flex items-center"><div class="bg-accent border-background absolute left-2 z-10 h-4 w-4 rounded-full border-2"></div><div class=ml-12><h3 class="text-foreground text-lg font-semibold">August 2025</h3><p class="text-muted-foreground text-xs">7
57+
posts</p></div></div><div class="ml-12 space-y-3"><article class="group bg-card border-border hover:bg-accent/50 rounded-lg border p-4 transition-all duration-300"><div class="flex items-center justify-between gap-4"><div class="min-w-0 flex-1"><h4 class="text-foreground group-hover:text-primary mb-3 font-medium transition-colors duration-200"><a href=/posts/git-whitelist/ class=block>Git Whitelist</a></h4><div class="text-muted-foreground flex items-center gap-4 text-xs"><div class="flex items-center gap-1"><svg class="h-3 w-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5A2 2 0 003 7v12a2 2 0 002 2z"/></svg>
58+
<time datetime=2025-08-08>08-08</time></div><div class="flex items-center gap-1"><svg class="h-3 w-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3A9 9 0 113 12a9 9 0 0118 0z"/></svg>
59+
<span>2
60+
min</span></div></div></div></div></article><article class="group bg-card border-border hover:bg-accent/50 rounded-lg border p-4 transition-all duration-300"><div class="flex items-center justify-between gap-4"><div class="min-w-0 flex-1"><h4 class="text-foreground group-hover:text-primary mb-3 font-medium transition-colors duration-200"><a href=/posts/fastapi-parameters-and-validations/ class=block>FastAPI Parameters and Validations</a></h4><div class="text-muted-foreground flex items-center gap-4 text-xs"><div class="flex items-center gap-1"><svg class="h-3 w-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5A2 2 0 003 7v12a2 2 0 002 2z"/></svg>
5861
<time datetime=2025-08-07>08-07</time></div><div class="flex items-center gap-1"><svg class="h-3 w-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 8v4l3 3m6-3A9 9 0 113 12a9 9 0 0118 0z"/></svg>
5962
<span>5
6063
min</span></div></div></div></div></article><article class="group bg-card border-border hover:bg-accent/50 rounded-lg border p-4 transition-all duration-300"><div class="flex items-center justify-between gap-4"><div class="min-w-0 flex-1"><h4 class="text-foreground group-hover:text-primary mb-3 font-medium transition-colors duration-200"><a href=/posts/fastapi-parameters/ class=block>FastAPI Parameters</a></h4><div class="text-muted-foreground flex items-center gap-4 text-xs"><div class="flex items-center gap-1"><svg class="h-3 w-3" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7V3m8 4V3m-9 8h10M5 21h14a2 2 0 002-2V7a2 2 0 00-2-2H5A2 2 0 003 7v12a2 2 0 002 2z"/></svg>

public/en/sitemap.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?xml version="1.0" encoding="utf-8" standalone="yes"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"><url><loc>https://starslayerx.github.io/posts/fastapi-parameters-and-validations/</loc><lastmod>2025-08-07T10:30:00+08:00</lastmod></url><url><loc>https://starslayerx.github.io/posts/</loc><lastmod>2025-08-07T10:30:00+08:00</lastmod><xhtml:link rel="alternate" hreflang="zh-CN" href="https://starslayerx.github.io/zh-cn/posts/"/><xhtml:link rel="alternate" hreflang="en-US" href="https://starslayerx.github.io/posts/"/></url><url><loc>https://starslayerx.github.io/posts/fastapi-parameters/</loc><lastmod>2025-08-06T10:30:00+08:00</lastmod></url><url><loc>https://starslayerx.github.io/posts/python-tricks/</loc><lastmod>2025-08-05T10:30:00+08:00</lastmod></url><url><loc>https://starslayerx.github.io/posts/executing-arbitrary-python-code-from-a-comment/</loc><lastmod>2025-08-04T10:30:00+08:00</lastmod></url><url><loc>https://starslayerx.github.io/posts/how-fastapi-works/</loc><lastmod>2025-08-03T10:30:00+08:00</lastmod></url><url><loc>https://starslayerx.github.io/posts/blaugust/</loc><lastmod>2025-08-01T10:00:00+08:00</lastmod><xhtml:link rel="alternate" hreflang="zh-CN" href="https://starslayerx.github.io/zh-cn/posts/blaugust/"/><xhtml:link rel="alternate" hreflang="en-US" href="https://starslayerx.github.io/posts/blaugust/"/></url><url><loc>https://starslayerx.github.io/</loc><lastmod>2023-01-01T08:00:00-07:00</lastmod><xhtml:link rel="alternate" hreflang="zh-CN" href="https://starslayerx.github.io/zh-cn/"/><xhtml:link rel="alternate" hreflang="en-US" href="https://starslayerx.github.io/"/></url><url><loc>https://starslayerx.github.io/archives/</loc><xhtml:link rel="alternate" hreflang="zh-CN" href="https://starslayerx.github.io/zh-cn/archives/"/><xhtml:link rel="alternate" hreflang="en-US" href="https://starslayerx.github.io/archives/"/></url><url><loc>https://starslayerx.github.io/categories/</loc><xhtml:link rel="alternate" hreflang="zh-CN" href="https://starslayerx.github.io/zh-cn/categories/"/><xhtml:link rel="alternate" hreflang="en-US" href="https://starslayerx.github.io/categories/"/></url><url><loc>https://starslayerx.github.io/tags/</loc><xhtml:link rel="alternate" hreflang="zh-CN" href="https://starslayerx.github.io/zh-cn/tags/"/><xhtml:link rel="alternate" hreflang="en-US" href="https://starslayerx.github.io/tags/"/></url></urlset>
1+
<?xml version="1.0" encoding="utf-8" standalone="yes"?><urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml"><url><loc>https://starslayerx.github.io/posts/git-whitelist/</loc><lastmod>2025-08-08T10:00:00+08:00</lastmod></url><url><loc>https://starslayerx.github.io/posts/</loc><lastmod>2025-08-08T10:00:00+08:00</lastmod><xhtml:link rel="alternate" hreflang="zh-CN" href="https://starslayerx.github.io/zh-cn/posts/"/><xhtml:link rel="alternate" hreflang="en-US" href="https://starslayerx.github.io/posts/"/></url><url><loc>https://starslayerx.github.io/posts/fastapi-parameters-and-validations/</loc><lastmod>2025-08-07T10:30:00+08:00</lastmod></url><url><loc>https://starslayerx.github.io/posts/fastapi-parameters/</loc><lastmod>2025-08-06T10:30:00+08:00</lastmod></url><url><loc>https://starslayerx.github.io/posts/python-tricks/</loc><lastmod>2025-08-05T10:30:00+08:00</lastmod></url><url><loc>https://starslayerx.github.io/posts/executing-arbitrary-python-code-from-a-comment/</loc><lastmod>2025-08-04T10:30:00+08:00</lastmod></url><url><loc>https://starslayerx.github.io/posts/how-fastapi-works/</loc><lastmod>2025-08-03T10:30:00+08:00</lastmod></url><url><loc>https://starslayerx.github.io/posts/blaugust/</loc><lastmod>2025-08-01T10:00:00+08:00</lastmod><xhtml:link rel="alternate" hreflang="zh-CN" href="https://starslayerx.github.io/zh-cn/posts/blaugust/"/><xhtml:link rel="alternate" hreflang="en-US" href="https://starslayerx.github.io/posts/blaugust/"/></url><url><loc>https://starslayerx.github.io/</loc><lastmod>2023-01-01T08:00:00-07:00</lastmod><xhtml:link rel="alternate" hreflang="zh-CN" href="https://starslayerx.github.io/zh-cn/"/><xhtml:link rel="alternate" hreflang="en-US" href="https://starslayerx.github.io/"/></url><url><loc>https://starslayerx.github.io/archives/</loc><xhtml:link rel="alternate" hreflang="zh-CN" href="https://starslayerx.github.io/zh-cn/archives/"/><xhtml:link rel="alternate" hreflang="en-US" href="https://starslayerx.github.io/archives/"/></url><url><loc>https://starslayerx.github.io/categories/</loc><xhtml:link rel="alternate" hreflang="zh-CN" href="https://starslayerx.github.io/zh-cn/categories/"/><xhtml:link rel="alternate" hreflang="en-US" href="https://starslayerx.github.io/categories/"/></url><url><loc>https://starslayerx.github.io/tags/</loc><xhtml:link rel="alternate" hreflang="zh-CN" href="https://starslayerx.github.io/zh-cn/tags/"/><xhtml:link rel="alternate" hreflang="en-US" href="https://starslayerx.github.io/tags/"/></url></urlset>

0 commit comments

Comments
 (0)