如何递归地忽略 git 存储库中的所有隐藏目录/文件?
我想让 Git 忽略所有隐藏的文件和目录。 即
.aptitude
.ssh/
.bash_rc
config/.hidden
是否有一个简单的规则可以覆盖这个而无需专门添加每个条目?
I'd like to have Git ignore all hidden files and directories.
i.e.
.aptitude
.ssh/
.bash_rc
config/.hidden
Is there a simple rule to cover this without specifically adding each entry?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需向
.gitignore
添加一个模式编辑: 添加
.gitignore
文件本身(如果尚未提交则很重要)。Just add a pattern to
.gitignore
Edit: Added the
.gitignore
file itself (matters if it is not yet commited)..gitignore 只会影响尚未“添加”的文件。
使新的 .gitignore 条目影响所有文件
git commit -a -m "Pre .gitignorechanges"
git rm -r --cached .
git add .
git commit -a -m "Post .gitignore 更改"
git status
应该输出“没有什么可提交的(工作目录干净)”
`
.gitignore will only effect files that haven't been 'added' already.
To make new .gitignore entries affect all files
git commit -a -m "Pre .gitignore changes"
git rm -r --cached .
git add .
git commit -a -m "Post .gitignore changes"
git status
should output "nothing to commit (working directory clean)"
`
在 .git/info/exclude 中,添加以下行:
这将使计算机上每个存储库默认递归地忽略所有隐藏/点文件。这样就不需要为每个存储库创建单独的 .gitignore 文件。
In
.git/info/exclude
, add this line:This will make ignoring all hidden/dot files recursively the default for every repository on the machine. A separate
.gitignore
file for every repo is not needed this way.对我来说
.*
不起作用,不会忽略例如notebooks/templates/.ipynb_checkpoints/
。所做的工作是:For me
.*
didn't work, doesn't ignore e.g.notebooks/templates/.ipynb_checkpoints/
. What did work is: