如何在 git 存储库中递归忽略所有隐藏的目录/文件?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8021441/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to ignore all hidden directories/files recursively in a git repository?
提问by Poe
I'd like to have Git ignore all hidden files and directories. i.e.
我想让 Git 忽略所有隐藏的文件和目录。IE
.aptitude
.ssh/
.bash_rc
config/.hidden
.aptitude
.ssh/
.bash_rc
config/.hidden
Is there a simple rule to cover this without specifically adding each entry?
是否有一个简单的规则来涵盖这一点而无需专门添加每个条目?
回答by Daniel B?hmer
Just add a pattern to .gitignore
只需添加一个模式 .gitignore
.*
!/.gitignore
Edit:Added the .gitignore
file itself (matters if it is not yet commited).
编辑:添加了.gitignore
文件本身(如果尚未提交很重要)。
回答by Nat Darke
.gitignorewill only effect files that haven't been 'added' already.
.gitignore只会影响尚未“添加”的文件。
To make new .gitignore entries affect all files
使新的 .gitignore 条目影响所有文件
- Make changes to .gitignore
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)" `
- 对 .gitignore 进行更改
git commit -a -m "Pre .gitignore changes"
git rm -r --cached .
git add .
git commit -a -m "Post .gitignore changes"
git status
应该输出“没有提交(工作目录干净)”`
回答by slayedbylucifer
In .git/info/exclude
, add this line:
在 中.git/info/exclude
,添加这一行:
.*
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.
这将使忽略所有隐藏/点文件递归成为机器上每个存储库的默认值。.gitignore
这种方式不需要每个 repo 的单独文件。