如何在 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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:14:57  来源:igfitidea点击:

How to ignore all hidden directories/files recursively in a git repository?

gitgitignore

提问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 .gitignorefile 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 条目影响所有文件

  1. Make changes to .gitignore
  2. git commit -a -m "Pre .gitignore changes"
  3. git rm -r --cached .
  4. git add .
  5. git commit -a -m "Post .gitignore changes"
  6. git statusshould output "nothing to commit (working directory clean)" `
  1. 对 .gitignore 进行更改
  2. git commit -a -m "Pre .gitignore changes"
  3. git rm -r --cached .
  4. git add .
  5. git commit -a -m "Post .gitignore changes"
  6. 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 .gitignorefile for every repo is not needed this way.

这将使忽略所有隐藏/点文件递归成为机器上每个存储库的默认值。.gitignore这种方式不需要每个 repo 的单独文件。