git is not recognizing entries in my gitignore file

I followed directions found here and I am still ending up with the same handful of files. Even if I specifically invoke git -rm --cached those/files*, when I call git status I still see those same files in under "Untracked files:"

Here is what my gitignore file looks like:

# Files that exceed 100MB #

How do I make it so that these files, along with any other files I enter into .gitignore which exceeds 100MB in the future, are not even untracked, but are ignored altogether?

2 answers

  • answered 2018-10-11 19:55 CelineDion

    Damn, I think I just realized the problem: for some reason, gitignore will not pick up on files preceded with a dot. So I have to remove these dots for gitignore to work, apparently. If someone could tell me why that is, it would be greatly appreciated.

  • answered 2018-10-11 20:54 torek

    There is no built in "ignore by size". You could write a program that inspects files, and for those that exceed some size threshold, updates the .gitignore. A very simple shell script version to find "large files" is:

    find . -name .git -prune -o -size +100M -print | cut -c3-

    (the cut -c3- discards the leading ./ that this find prints).

    You can run these names through git check-ignore to see if they are already ignored, and if not, add them to .gitignore:

    [find expression as above] |
    while read -r name; do
         git check-ignore -q "$name" || printf '%s\n' $name >> .gitignore

    Note that this assumes the .gitignore file itself will not grow so large as to cause problems. If it would, be sure to eliminate .gitignore as an ignored file even if .gitignore exceeds your size threshold, e.g.:

    find . -name .git -prune -o -name .gitignore -prune -o -size +$limit -print

    where $limit is the size threshold (100M for 100 megabytes, 10k for 10 kbytes, etc).