目的是防止新手乱操作,老手误操作。
在每个git项目根目录下有个隐藏文件夹.git, 该文件夹下有个hooks目录,复制hooks目录下的pre-push.smaple并更名为pre-push文件,即 项目根目录/.git/hooks/pre-push 文件,编辑粘贴以下代码:
#!/bin/sh git diff-tree --no-commit-id --name-only HEAD -z -- | xargs -0 sh -c ' for f; do if git show :"$f" | grep "< <<<<<< HEAD"; then echo "$f has some conflicts,can not push" exit 1; fi if git show :"$f" |grep ">>>>>>>"; then echo "$f has some conflicts,can not push" exit 1; fi done exit 0; ' -
然后保存即可。
来源于:http://blog.sina.com.cn/s/blog_61d8d9640102vaht.html