如何递归地忽略 git 存储库中的所有隐藏目录/文件?

发布于 2024-12-14 08:53:19 字数 211 浏览 5 评论 0原文

我想让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

月亮坠入山谷 2024-12-21 08:53:20

只需向 .gitignore 添加一个模式

.*
!/.gitignore

编辑: 添加 .gitignore 文件本身(如果尚未提交则很重要)。

Just add a pattern to .gitignore

.*
!/.gitignore

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

樱花坊 2024-12-21 08:53:20

.gitignore 只会影响尚未“添加”的文件。

使新的 .gitignore 条目影响所有文件

  1. 对 .gitignore 进行更改
  2. git commit -a -m "Pre .gitignorechanges"
  3. git rm -r --cached .
  4. git add .
  5. git commit -a -m "Post .gitignore 更改"
  6. git status
    应该输出“没有什么可提交的(工作目录干净)”
    `

.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)"
    `
在梵高的星空下 2024-12-21 08:53:20

在 .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.

秉烛思 2024-12-21 08:53:20

对我来说 .* 不起作用,不会忽略例如 notebooks/templates/.ipynb_checkpoints/。所做的工作是:

/**/.*  # ignore all dotted files
/**/.*/ # ignore all dotted folders
!/.gitignore  # except `gitignore` :)

For me .* didn't work, doesn't ignore e.g. notebooks/templates/.ipynb_checkpoints/. What did work is:

/**/.*  # ignore all dotted files
/**/.*/ # ignore all dotted folders
!/.gitignore  # except `gitignore` :)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文