Limiting file size in git repository

前端 未结 11 1503
星月不相逢
星月不相逢 2020-12-02 14:55

I\'m currently thinking of changing my VCS (from subversion) to git. Is it possible to limit the file size within a commit in a git repository? For e. g. subversion there is

11条回答
  •  半阙折子戏
    2020-12-02 15:10

    You can use a hook, either pre-commit hook (on client), or a update hook (on server). Do a git ls-files --cached (for pre-commit) or git ls-tree --full-tree -r -l $3 (for update) and act accordingly.

    git ls-tree -l would give something like this:

    100644 blob 97293e358a9870ac4ddf1daf44b10e10e8273d57    3301    file1
    100644 blob 02937b0e158ff8d3895c6e93ebf0cbc37d81cac1     507    file2
    

    Grab the forth column, and it is the size. Use git ls-tree --full-tree -r -l HEAD | sort -k 4 -n -r | head -1 to get the largest file. cut to extract, if [ a -lt b ] to check size, etc..

    Sorry, I think if you are a programmer, you should be able to do this yourself.

提交回复
热议问题