Git — add all files that are smaller than X megabytes

后端 未结 2 1314
执念已碎
执念已碎 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.

提交回复
热议问题