Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
当我们编码时,有时我们会在我们的项目中编写调试代码,所以我想写一个钩子来检查更改中是否有调试代码。举些例子。
console.log('this is debug code');//DEBUG
让钩子检查 //DEBUG 如果文件中有 //DEBUG 给出错误说你的文件中有调试代码请在提交之前将其删除。
示例预提交挂钩非常接近您想要的。它位于 /.git/hooks/pre-commit.sample。您需要做的就是更改 diff 行的逻辑。
$(git diff --cached --name-only --diff-filter=A -z $against- 修改它,以便您转储实际的差异(删除 --name-only),然后将其通过管道传送到 grep 以查找 + 号和 DEBUG。
$(git diff --cached --name-only --diff-filter=A -z $against