git - 我是如何搞砸这个非常简单的 .gitignore 文件的?

标签 git gitignore

我只想跟踪目录中的一个文件。该文件是buildout.cfg。所以我首先运行git init。然后我创建了一个 .gitignore 文件,其完整内容如下:

* # Blacklist all files
!buildout.cfg # Whitelist the file I'm interested in

但是现在,当我运行命令 git add 时,git 会继续添加数十个文件 - 目录中的所有内容。

为什么?

最佳答案

根据man gitignore ,注释仅为整行。所以你应该尝试将注释移到不同的行:

# Blacklist all files
*
# Whitelist this file
!buildout.cfg

关于git - 我是如何搞砸这个非常简单的 .gitignore 文件的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12977534/

相关文章:

git - 如何在团队中使用 git tfs

git - 在 Gitlab 登录页面更改选项卡名称

wordpress - 忽略包含的文件夹,但不忽略其中的文件夹

git - 使用 Git 跟踪本地被忽略的文件

gitignore - 忽略 gitignore 中的 .blendX 文件

git - .npmignore 扩展/继承自 .gitignore

linux - GIT 不推送我的文件

git - 如何关闭 GIT_CURL_VERBOSE?

wordpress - Git - 无法推送 - "! [remote rejected] master -> master (Working directory has unstaged changes)"

vagrant - vagrant 中的全局 .gitignore