简体   繁体   中英

Why is .gitignore not working when I use git add *?

To satisfy github 100Mb requirement, I run the following to ignore some large files:

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

but when I run add * later, it is still adding the >100MB file to commit.

$ 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

How can I make this gitignore work? Thanks in advance for ideas and advices.

add: my intent is to make add * not track the large csv file any more, following answer does not seem to work.

Previously added files are not affected by, adding them later to gitignore. Take a backup of the files and delete the files locally and commit them. So, that they are not tracked by git. Now, Paste back the files to the original place and you can add the bigger filenames to gitignore. Now, git will not be tracking them, as they are considered fresh files.

Another way is to use, as suggested by @alfunx, git rm --cached <file> . The file will be removed from cache(index) and once you commit, the file will not be tracked anymore. You can also update .gitignore accordingly to avoid any further tracking of the file.

Read more about it in 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 .

Rather than ignore the file (often I will add it back by calling add . method in later time), there is a better way to resolve the issue, git lfs , see my usage below, this will help to push the large files to github.

 $git lfs install
 $git lfs track "*.csv"
 $git add .gitattributes
 $git add act_train.csv
 $git commit -m "test lfs"
 $git push

Done

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM