为什么 .gitignore 在我使用 git add * 时不起作用?
Why is .gitignore not working when I use git add *?
为了满足 github 100Mb 的要求,我 运行 以下忽略一些大文件:
$ find ./* -size +100M | cat >> .gitignore
但是当我 运行 稍后添加 * 时,它仍在添加 >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 文件,以下答案似乎不起作用。
之前添加的文件不受影响,以后添加到git忽略。备份文件并在本地删除文件并提交它们。因此,他们没有被 git 跟踪。现在,将文件粘贴回原始位置,您可以将更大的文件名添加到 gitignore。现在,git 将不会跟踪它们,因为它们被视为新文件。
另一种方法是按照@alfunx 的建议使用git rm --cached <file>
。该文件将从缓存(索引)中删除,一旦您提交,该文件将不再被跟踪。您还可以相应地更新 .gitignore 以避免对该文件进行任何进一步跟踪。
中阅读更多相关信息
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
.
与其忽略该文件(通常我会在稍后调用 add. 方法将其添加回来),还有更好的方法来解决这个问题,git lfs
,请参阅下面的用法,这将帮助将大文件推送到 github.
$git lfs install
$git lfs track "*.csv"
$git add .gitattributes
$git add act_train.csv
$git commit -m "test lfs"
$git push
完成
为了满足 github 100Mb 的要求,我 运行 以下忽略一些大文件:
$ find ./* -size +100M | cat >> .gitignore
但是当我 运行 稍后添加 * 时,它仍在添加 >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 文件,以下答案似乎不起作用。
之前添加的文件不受影响,以后添加到git忽略。备份文件并在本地删除文件并提交它们。因此,他们没有被 git 跟踪。现在,将文件粘贴回原始位置,您可以将更大的文件名添加到 gitignore。现在,git 将不会跟踪它们,因为它们被视为新文件。
另一种方法是按照@alfunx 的建议使用git rm --cached <file>
。该文件将从缓存(索引)中删除,一旦您提交,该文件将不再被跟踪。您还可以相应地更新 .gitignore 以避免对该文件进行任何进一步跟踪。
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
.
与其忽略该文件(通常我会在稍后调用 add. 方法将其添加回来),还有更好的方法来解决这个问题,git lfs
,请参阅下面的用法,这将帮助将大文件推送到 github.
$git lfs install
$git lfs track "*.csv"
$git add .gitattributes
$git add act_train.csv
$git commit -m "test lfs"
$git push
完成