git pre-push hook
This article introduces git pre-push hook.
Problem
In Lean project, we use a modified version of Google’s C++ style checker. I want to automatically run the checker over the changed files before I push commits to git repositories. This is useful because it prevents me from accidentally pushing the commits which contain style problems.
Solution: git pre-push hook
Since git 1.8.2, git introduced pre-push hook which is executed before actual push operation is performed. The following two steps solve the problem.
- Create
<PROJECT_ROOT>/.git/hooks/pre-pushfile with the following contents:
#!/usr/bin/env bash
IFS=' '
DIR="$( cd "$( dirname "$0" )" && pwd )"
CHECKER=$DIR/../../src/cmake/Modules/cpplint.py
while read local_ref local_sha remote_ref remote_sha;
do
CHANGED_FILES=`git diff --name-only $local_sha $remote_sha | grep '\(cpp\|h\)$'`
if [ ! -z "$CHANGED_FILES" -a "$CHANGED_FILES" != " " ]; then
echo $CHANGED_FILES | xargs $CHECKER
RET=$?
if [ $RET -ne 0 ]; then
echo "There is error(s) from style-check. Please fix them before push to the repo."
exit $RET
fi
fi
done
exit 0
- Give “exec” permission to the file
chmod +x <PROJECT_ROOT>/.git/hooks/pre-push
Note that you need to change CHECKER variable if you want to use other checkers.
git pre-push hook的更多相关文章
- git commit -m "XX"报错 pre -commit hook failed (add --no-verify to bypass)问题
在同步本地文件到线上仓库的时候 报错 pre -commit hook failed (add --no-verify to bypass) 当你在终端输入git commit -m "xx ...
- 解决git pull/push每次都需要输入密码问题 和 HttpRequestException encountered
如果我们git clone的下载代码的时候是连接的https://而不是git@git (ssh)的形式,当我们操作git pull/push到远程的时候,总是提示我们输入账号和密码才能操作成功,频繁 ...
- git server side hook 试用
git 的hook 是一个很方便的功能,我们可以使用hook 做好多处理,比如client side hook 进行 提交格式校验,server side 进行ci/cd 处理 测试使用docker- ...
- git问题--Push rejected: Push to origin/master was rejected
解决git问题 Push rejected: Push to origin/master was rejected 意思是git拒绝合并两个不相干的东西 此时你需要在打开Git Bash,然后进入相应 ...
- git一键push至github脚本
######################################################################### # File Name: push.sh # Aut ...
- 使用 expect 重启失败的 git pull/push 操作
问题的提出 最近使用 github 上传.下载项目代码时,经常会卡很久,有时候在命令行打了 git push 然后就去上厕所了,结果等我回来的时候,发现 push 早已经失败了,还得重新提交一下.如果 ...
- SourceTree/git解决pre-commit hook failed的问题
一. git commit -m 'xxx' 出现问题 今天在上传项目的时候在commit阶段遇到一个问题,无论是在Sourcetree上传还是用命令git commit -m 'xxx'都报了一下错 ...
- git remote: error: hook declined to update
提交一个项目,push的时候,报错: remote: error: File xxx.rar is MB; this exceeds Git@OSC's file size limit of 100 ...
- 使用Git的Push出现rejected - non-fast-forward错误
通过查阅资料,发现是文件冲突问题,即本地和远程的Repository中的文件出现了冲突所致,重新检查了一下,发现是在建立Repository时,添加了ReadMe.txt文件,导致和本地得项目分支不一 ...
- 配置git同时push到两个远端库的简单方法
最近在写一个开源的论坛系统,在发布代码时选择了github和coding这两个平台,我手懒,不想敲两次git push了,所以说突然有了一个很奇怪的需求:用一条git push同时push到两个远端代 ...
随机推荐
- nginx1.14.0版本高可用——keepalived双机热备
nginx不支持主从,所以我们需要使用keepalive支持高可用. keepalived重要知识点 在局域网内,每个主机上各安装一个keepalived,注意关闭防火墙firewalld,然后设定一 ...
- MFC 使用Skin++ 美化皮肤
查了好几天关于MFC应用程序换肤的资料,经过各种莫名其妙的问题的困扰,现分享一下自己的体会.希望可 以避免一些弯路.另外会在附上一些资源. 环境:Windows 7 + VS2012 + SkinSh ...
- Docker容器开机自动启动
部署项目服务器时,为了应对停电等情况影响正常web项目的访问,会把Docker容器设置为开机自动启动. 在使用docker run启动容器时,使用--restart参数来设置: # docker r ...
- atom插件
1.Sync Settings 搭配github,同步你的atom插件信息,配置信息,让你轻松实现一台电脑配置,多台电脑共享. 2.Emmet 能够基于Emmet语法产生HTML,做过前段开发的不会不 ...
- 微信小程序tab栏切换
Wxml代码:<view class="body"> <view class="nav bc_white"> <view clas ...
- 河北省重大技术需求征集系统原型(MVC框架业务流程简介)
这段时间了解了一些MVC框架. 一.MVC简介 MVC 是一种使用 MVC(Model View Controller 模型-视图-控制器)设计创建 Web 应用程序的模式.它的模式是JSP + se ...
- Python爬虫简单介绍
相关环境: Python3 requests库 BeautifulSoup库 一.requests库简单使用 简单获取一个网页的源代码: import requests sessions = requ ...
- Android 开发 关于APP无法安装到Android模拟器上的问题
我们在创建一个app后,打算安装到Android模拟器上.可能会出现无法安装,或者提示已经安装无法卸载的问题.这个时候需要添加兼容CPU. 选择 build.gradle 文件打开添加如下代码: an ...
- strace参数
strace参数 -c 统计每一系统调用的所执行的时间,次数和出错的次数等. -d 输出strace关于标准错误的调试信息. -f 跟踪由fork调用所产生的子进程. -ff 如果提供-o filen ...
- django 创建视图和APP
.创建视图views 1.在项目目录下创建views.py文件 2.from django.http import HttpResponse 3.在urls 导入模板: from django.con ...