Git:在提交/推送之前运行过滤器? [英] Git: Run through a filter before commiting/pushing?

查看:165
本文介绍了Git:在提交/推送之前运行过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在提交之前通过过滤器运行更改的文件?我希望确保文件遵循项目的编码标准。

Is there a way to run the changed files through a filter before doing the commit? I wish to make sure the files follows the coding standards for the project.

我也想在提交/ push实际发生之前编译和运行一些测试,所以我知道repo中的一切实际上是工作。

I would also like to compile and run some test before the commit/push actually takes place, so I know everything in the repo actually works.

推荐答案

预提交钩子。阅读 git钩子。 Git Book有一个关于如何编写Ruby脚本来运行RSpec测试的示例,例如。

Pre-commit hooks. Read up on git hooks. The Git Book has an example of how to write a Ruby script to run RSpec tests, for instance.

您只需将可执行文件保存为.git / hooks / pre-commit - 使用hashbang指定语言。它只是一个普通的shell脚本,虽然你可以使用任何脚本语言,只要它返回1如果有一个问题,如果没有,则返回0。

You just save the executable as .git/hooks/pre-commit - using a hashbang to specify the language. It is just an ordinary shell script, although you can use any scripting language, so long as it returns 1 if there is a problem and 0 if there isn't.

这篇关于Git:在提交/推送之前运行过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆