You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用.gitignore作为允许列表备份~/.config特定文件夹遇问题

解决Git忽略规则不生效的问题

问题根源在于*会忽略所有文件和目录,包括你要保留的子目录本身。Git不会扫描已被忽略的目录,所以后续!Jetbrains/**这类针对目录内容的排除规则根本无法生效。

修改你的.gitignore文件,先排除目录本身,再覆盖目录下的内容规则:

*
!.gitignore
!Jetbrains/
!Jetbrains/**
!Google/
!Google/**
!autostart/
!autostart/**
!git/
!git/**
!nvim/
!nvim/**
!obsidian/
!obsidian/**
!polybar/
!polybar/**

如果想更简洁,也可以用这种写法(排除目录后,默认会包含目录下所有内容,!*/**是兜底确保子目录内容被识别):

*
!.gitignore
!Jetbrains/
!Google/
!autostart/
!git/
!nvim/
!obsidian/
!polybar/
!*/**

修改完成后,执行以下命令让Git重新识别文件:

git add . -f
git commit -m "提交指定配置目录"

(首次添加用-f强制覆盖之前的忽略规则,之后正常执行git add . && git commit即可)

内容的提问来源于stack exchange,提问作者isi_ko

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.13 14:25:24