是否可以自动拆分 Github 比较视图的提交?

Is it possible to automatically split a commit for Github compare view?

在我们公司,代码审查是通过添加注释在 Github 比较视图中完成的。当然你可以使用 difftool 或 someting。但是我想知道是否有一种方法可以在超过 the Github limits?

时自动警告/拆分提交

您可以使用预提交 hook 来防止大量提交。例如。要检查 diff 的行数,请将以下内容保存为 [REPO PATH]/.git/hooks/pre-commit 并使其可执行(例如 chmod +x on linux):

#!/usr/bin/env bash
[[ $(git diff --cached | wc -l) > 300 ]] && { echo "Commit too long"; exit 1; }

或检查文件大小:

tmp=$(mktemp /tmp/git_XXXXX)
git diff --cached > "$tmp"
[[ $(ls -l "$tmp" | awk '{print }') > 10000 ]] && { echo "Commit too large"; exit 1; }