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

﹥>﹥吖頭↗ 提交于 2019-12-11 20:23:03

问题


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; }  


来源:https://stackoverflow.com/questions/33631073/is-it-possible-to-automatically-split-a-commit-for-github-compare-view

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!