git - 为什么当我使用 git add * 时 .gitignore 不起作用?

标签 git gitignore ignore

为了满足 github 100Mb 要求,我运行以下命令来忽略一些大文件:

$ find ./* -size +100M | cat >> .gitignore

但是当我稍后运行 add * 时,它仍然添加要提交的 >100MB 文件。

$ git add *
warning: LF will be replaced by CRLF in hw1/input/act_test.csv.
The file will have its original line endings in your working directory

我怎样才能让这个 gitignore 工作? 预先感谢您的想法和建议。

添加: 我的目的是让 add * 不再跟踪大型 csv 文件,以下答案似乎不起作用。

最佳答案

之前添加的文件不受影响,稍后将它们添加到 gitignore。备份文件并在本地删除文件并提交。因此,它们不会被 git 跟踪。现在,将文件粘贴回原来的位置,您可以将更大的文件名添加到 gitignore。现在,git 将不会跟踪它们,因为它们被视为新文件。

另一种方法是使用@alfunx建议的git rm --cached <file> 。该文件将从缓存(索引)中删除,一旦提交,该文件将不再被跟踪。您还可以相应地更新 .gitignore 以避免进一步跟踪该文件。

gitignore documentation 中了解更多相关信息

A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected; see the NOTES below for details.

[...]

NOTES

The purpose of gitignore files is to ensure that certain files not tracked by Git remain untracked.

To stop tracking a file that is currently tracked, use git rm --cached.

关于git - 为什么当我使用 git add * 时 .gitignore 不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53531624/

相关文章:

javascript - 如何限制 git 跟踪/更新本地更改?

git 忽略文件头

git - 忽略对git中文件的特定更改,而不是整个文件

Git diff 报告本地更改 'old mode'/'new mode'

git - Jenkins 创建一个工作来构建许多 repo

Git 版本兼容性

svn - 如何在 svn add 期间关闭跳过 .a 文件

git - ssh : connect to host gitlab. com 端口 22:连接超时

Gitignore 错误地排除了子文件

git - 如何忽略 git 中的文件或目录,无论是跟踪、未跟踪还是提交的一部分