必须统一忽略的文件包括:.gitignore 中的 node_modules/、dist/、build/、coverage/;.vscode/settings.json 中的 files.exclude 和 search.exclude(内容一致,用 **/node_modules 等递归匹配);敏感文件如 .env 需忽略但保留 .env.example 模板。

VSCode 团队协作中哪些文件必须统一忽略
团队项目里,不统一忽略某些文件会导致提交冲突、本地路径泄露、IDE 行为不一致。核心是区分三类文件:.gitignore 管 Git 跟踪、files.exclude 控资源管理器显示、search.exclude 控搜索范围——三者不能互相替代。
必须进 .gitignore 的(放在项目根目录):
-
node_modules/、dist/、build/、coverage/—— 这些生成或依赖目录绝不能提交 -
.vscode/settings.json(除非团队强制缩进/换行符等风格)—— 否则每人改一次就触发 diff -
.env、local.config.js等含敏感配置的文件 —— 用!.env.example保留模板
必须进 .vscode/settings.json 的(工作区级):
-
"files.exclude"和"search.exclude"都要配,且内容尽量一致,例如:
"files.exclude": {
"**/node_modules": true,
"**/dist": true,
"**/*.log": true
},
"search.exclude": {
"**/node_modules": true,
"**/dist": true,
"**/*.log": true
}
注意:**/node_modules 比 node_modules/ 更可靠,前者递归匹配所有层级,后者只匹配项目根下的目录。
为什么 .vscode/settings.json 不能直接提交给所有人
因为 VSCode 工作区设置会覆盖用户级设置,但不同成员的开发环境可能差异很大:有人用 Prettier,有人用 ESLint;有人开自动保存,有人关;有人装了 CodeGeeX,有人没装。盲目提交 .vscode/settings.json 容易引发以下问题:
使用ydata-profiling(前身为pandas-profiling)生成全面的数据质量报告,包含相关性分析、缺失值模式和基数检测。导出交互式HTML仪表板和JSON摘要。
- 强制开启
editor.formatOnSave,但对方没装对应 formatter,保存时疯狂报错 - 写死
"eslint.nodePath"指向自己机器上的全局 node_modules,别人打开就失效 - 包含
"emeraldwalk.runonsave"等非通用扩展配置,其他成员看不到效果还困惑
推荐做法:只在 .vscode/settings.json 里放「与项目结构强相关」的排除规则(如 dist/、public/generated/),其他编辑器行为类设置全部走用户级或靠 .editorconfig 统一。
CodeGeeX / ESLint / Clang-Format 各自的忽略逻辑互不兼容
VSCode 不是“一个开关管所有”,每个工具读自己的配置,且不共享 .gitignore 或 files.exclude:
-
CodeGeeX只认"codegeex.ignorePatterns"字段(数组格式),必须重启窗口才生效;漏写**/前缀只会忽略同级目录 -
ESLint 扩展在编辑器内完全无视.eslintignore,真正起作用的是overrides.files配置项(在.eslintrc.cjs里)或eslint.validate设置 -
Clang-Format支持.clang-format-ignore文件(每行一个 glob),但该文件必须和源码在同一卷宗下;DisableFormat: true是全局禁用,不推荐
示例:想让 ESLint 跳过测试文件,但 CodeGeeX 仍分析它们,就得分别配置:
// .eslintrc.cjs
overrides: [{
files: ["**/*.test.ts", "**/*.spec.ts"],
rules: {}
}]
// .vscode/settings.json "codegeex.ignorePatterns": ["**/dist/**", "**/node_modules/**"]
修改后文件没变灰?先查 Git 状态,不是 VSCode 缓存
VSCode 资源管理器里文件颜色(灰色+删除线)完全依赖 git status --ignored 输出,不是自己解析 .gitignore。所以常见“改了 .gitignore 但文件还是黑的”原因只有两个:
- 文件已被 Git 跟踪(
git status显示为M或A),此时加.gitignore无效,必须git rm --cached <file> -
.gitignore不在 Git 仓库根目录(git rev-parse --show-toplevel可验证),比如误放在src/下,它只对src/及子目录生效
执行完 git rm --cached 后,VSCode 通常 1–2 秒内自动刷新状态;若没反应,手动运行命令面板 → Developer: Reload Window 即可,不需要全量重启。

















