At our company code reviews are done in Github compare view by adding comments. Of course you can use difftool or someting. But I'd like to know if there is a way to automatically warn / split a commit when it exceeds the Github limits?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
You can use a pre-commit hook to prevent large commits. E.g. to check the diff's number of lines, save the following as [REPO PATH]/.git/hooks/pre-commit
and make it executable (e.g. chmod +x
on linux):
#!/usr/bin/env bash
[[ $(git diff --cached | wc -l) > 300 ]] && { echo "Commit too long"; exit 1; }
or check file size:
tmp=$(mktemp /tmp/git_XXXXX)
git diff --cached > "$tmp"
[[ $(ls -l "$tmp" | awk '{print $5}') > 10000 ]] && { echo "Commit too large"; exit 1; }