Git: Run through a filter before commiting/pushing?

穿精又带淫゛_ 提交于 2019-12-19 09:49:33

问题


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.

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.


回答1:


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.

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.




回答2:


For the filter part, I would recommend a smudge/clear driver, with the 'clear' script containing all the formatting or checking you need (executing on commit)

You can declare this git attribute filter driver only for certain types of files, only for certain directories within your repo.



来源:https://stackoverflow.com/questions/2638772/git-run-through-a-filter-before-commiting-pushing

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