为了满足 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/