Git — add all files that are smaller than X megabytes

后端 未结 2 1311
执念已碎
执念已碎 2020-12-10 07:08

I\'m using git to manage a non-coding-project folder that has some large files scattered all over the place.

I\'m not interesting in moving the files around as they

相关标签:
2条回答
  • 2020-12-10 08:02

    There are no flags to git that will do what you want. However, there are a lot of other utilities available that would work just fine...such as the find command. To add all files smaller than 4 MB:

    find * -size -4M -type f -print | xargs git add
    

    This assumes that you have no filenames containing spaces (e.g., "my important file"). If you have such files, then:

    find * -size -4M -type f -print0 | xargs -0 git add
    

    UPDATE: Note that I've replaced . with * here, because otherwise it will find (and try to add) things in your .git directory, which is not helpful.

    0 讨论(0)
  • 2020-12-10 08:13

    Building off of larsks's answer, you could do the opposite to add the large files to your .gitignore

    echo "# Files over 4mb" >> .gitignore
    find * -size +4M -type f -print >> .gitignore
    
    0 讨论(0)
提交回复
热议问题