简体   繁体   English

Git:如何忽略隐藏目录?

[英]Git: how to ignore hidden directories?

I'd like to have Git ignore all hidden files and directories, ie .aptitude , .ssh/ and .bash_rc . 我想让Git忽略所有隐藏的文件和目录,即.aptitude.ssh/.bash_rc Is there a simple rule to cover this without specifically adding each entry? 是否有一个简单的规则来覆盖这个而不是专门添加每个条目?

Just add a pattern to .gitignore 只需在.gitignore添加一个模式即可

.*
!/.gitignore

Edit: Added the .gitignore file itself (matters if it is not yet commited). 编辑:添加.gitignore文件本身(如果尚未提交则很重要)。

.gitignore will only effect files that haven't been 'added' already. .gitignore只会影响尚未“添加”的文件。

To make new .gitignore entries affect all files 要使新的.gitignore条目影响所有文件

  1. Make changes to .gitignore 对.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 should output "nothing to commit (working directory clean)" ` git status应输出“nothing to commit(working directory clean)”`

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. 这种方式不需要为每个repo单独的.gitignore文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM