好的,在 CodeWizard 的帮助下这个答案 https://stackoverflow.com/questions/42963854/list-files-not-tracked-by-git-lfs,我自己设法创建了一个很好的指南:
首先,设置您的存储库core.hooksPath
with:
git config core.hooksPath .githooks
其次,创建这个pre-commit
里面的文件.githooks
文件夹,以便可以跟踪(要点链接 https://gist.github.com/bitinn/834756d57f3d47df97937aab68162ae6),然后记得授予它执行权限chmod +x
.
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".
# Redirect output to stderr.
exec 1>&2
FILE_SIZE_LIMIT_KB=1024
CURRENT_DIR="$(pwd)"
COLOR='\033[01;33m'
NOCOLOR='\033[0m'
HAS_ERROR=""
COUNTER=0
# generate file extension filter from gitattributes for git-lfs tracked files
filter=$(cat .gitattributes | grep filter=lfs | awk '{printf "-e .%s$ ", $1}')
# before git commit, check non git-lfs tracked files to limit size
files=$(git diff --cached --name-only | sort | uniq | grep -v $filter)
while read -r file; do
if [ "$file" = "" ]; then
continue
fi
file_path=$CURRENT_DIR/$file
file_size=$(ls -l "$file_path" | awk '{print $5}')
file_size_kb=$((file_size / 1024))
if [ "$file_size_kb" -ge "$FILE_SIZE_LIMIT_KB" ]; then
echo "${COLOR}${file}${NOCOLOR} has size ${file_size_kb}KB, over commit limit ${FILE_SIZE_LIMIT_KB}KB."
HAS_ERROR="YES"
((COUNTER++))
fi
done <<< "$files"
# exit with error if any non-lfs tracked files are over file size limit
if [ "$HAS_ERROR" != "" ]; then
echo "$COUNTER files are larger than permitted, please fix them before commit" >&2
exit 1
fi
exit 0
现在,假设你两者都有.gitattributes
and git-lfs
设置正确,当您尝试执行此操作时,此预提交挂钩将运行git commit
并确保 git-lfs 不跟踪所有暂存文件(如您的.gitattributes
),将满足指定的文件大小限制。
您的存储库的任何新用户都需要进行设置core.hooksPath
他们自己,但除此之外,事情应该正常进行.
希望这可以帮助其他 Unity 开发人员应对不断增长的 git 存储库大小!