Git: how to ignore hidden directories?

2019-01-07 06:26发布

I'd like to have Git ignore all hidden files and directories, i.e. .aptitude, .ssh/ and .bash_rc. Is there a simple rule to cover this without specifically adding each entry?

标签: git gitignore
3条回答
男人必须洒脱
2楼-- · 2019-01-07 06:47

Just add a pattern to .gitignore

.*
!/.gitignore

Edit: Added the .gitignore file itself (matters if it is not yet commited).

查看更多
乱世女痞
3楼-- · 2019-01-07 06:49

.gitignore will only effect files that haven't been 'added' already.

To make new .gitignore entries affect all files

  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 status should output "nothing to commit (working directory clean)" `
查看更多
Anthone
4楼-- · 2019-01-07 06:54

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.

查看更多
登录 后发表回答