githooks
by Daniel Deutsch
由Daniel Deutsch
使用Githooks改善团队的开发工作流程 (Improve your team’s development workflow with Githooks)
Every product that is developed by more than one programmer needs to have some guidelines to harmonize the workflow.
由多个程序员开发的每个产品都需要有一些准则来协调工作流程。
A standardized software development workflow between programmers allows, for example:
程序员之间的标准化软件开发工作流程允许例如:
- faster engineering, since each developer can rely on a habitual activity 更快的工程设计,因为每个开发人员都可以依靠习惯性活动
- fewer errors, as the workflow itself shall be structured in a way to avoid some mistakes 错误更少,因为工作流本身的结构应避免某些错误
- easy integration of new members 轻松整合新成员
- improved log of history 改进的历史记录
One very easy to use feature are “Githooks”(if you are using Git for version control).
一个非常易于使用的功能是“ Githooks ”(如果您使用Git进行版本控制)。
In this article I want to show how easy it actually is to set up a few workflow guidelines with Githooks. This will allow your team to be on one page when developing software.
在本文中,我想展示使用Githooks设置一些工作流程指南实际上是多么容易。 这样一来,您的团队就可以在开发软件时集中在一页上。
目录 (Table of Contents)
Why Githooks?
为什么选择Githooks?
GitFlow and Checkout, Commit, Push
GitFlow和签出,提交,推送
Post-checkout
结帐后
Commit-msg
提交消息
Pre-push
预推
“Enforce” the hooks
“执行”挂钩
Fix one common problem
解决一个常见问题
Thanks
谢谢
为什么选择Githooks? (Why Githooks?)
Githooks are, as the word suggests, a hook for Git commands. Intuitively this makes sense. With Git you are essentially managing the workflow of a piece of software. Every Branch is a part of the whole piece. Every Commit is a building block of a Branch.
顾名思义,Githooks是Git命令的钩子。 直观上讲,这是有道理的。 使用Git,您实际上是在管理软件的工作流程。 每个分支都是整体的一部分。 每个提交都是分支的构建块。
So in order to standardize quality in software development, one must standardize actions in the building process of the product.
因此,为了标准化软件开发的质量,必须标准化产品构建过程中的动作。
There are many Git commands that can be hooked for setting standards. Remember, there are quite a few:
可以挂钩许多Git命令来设置标准。 请记住,有很多:
- applypatch-msg Applypatch-msg
- pre-applypatch 预先贴布
- post-applypatch 申请后
- pre-commit 预先提交
- prepare-commit-msg 准备提交消息
- commit-msg 提交消息
- post-commit 提交后
- pre-rebase 变基前
- post-checkout 结帐后
- post-merge 合并后
- pre-receive 预先接收
- pre-push 预推
- update 更新
- post-update 更新后
- pre-auto-gc 前自动gc
- post-rewrite 重写后
To establish an improved workflow you don’t have to use all of them. Focus on the few important ones. In my experience so far, those are:
要建立改进的工作流程,您不必全部使用。 专注于几个重要的方面。 根据我到目前为止的经验,这些是:
- commit-msg/pre-commit 提交消息/预提交
- post-checkout 结帐后
- pre-push 预推
Let me explain why.
让我解释一下原因。
GitFlow和签出,提交,推送 (GitFlow and Checkout, Commit, Push)
Using Git as version control system allows to set a workflow. I do this using the GitFlow method.
使用Git作为版本控制系统可以设置工作流程。 我使用GitFlow方法执行此操作。
It is basically to develop a piece of software where each feature is represented by a branch.
基本上是要开发一种软件,其中每个功能都由一个分支表示。
In the following examples I will always check naming with Regex tests or execute another script.
在以下示例中,我将始终使用Regex测试检查命名或执行其他脚本。
结帐后 (Post-checkout)
The increased importance of a branch allows for the first hook on “post-checkout”. It is triggered after a new branch is created with Git.
分支机构重要性的提高使您可以在“结帐后”上进行第一个挂钩。 使用Git创建新分支后,将触发该事件。
Often a naming convention is applied to make branches comparable and understand their use for the whole product.
通常使用命名约定来使分支具有可比性,并了解分支在整个产品中的用途。
You can create a simple shell script like this to ensure naming:
您可以创建一个简单的shell脚本,以确保命名:
提交消息 (Commit-msg)
In web development there are multiple libraries that help with setting up a hook for committing. Often they are not necessary, as simple scripts can be written by yourself as well.
在Web开发中,有多个库可帮助设置提交钩子。 通常它们不是必需的,因为您也可以自己编写简单的脚本。
See validation of a git message for example:
例如,请参见验证git消息:
预推 (Pre-push)
“Git push” is the process of “sharing” your branch with the team. It is often the last step before opening a pull-request for a merge with the main branch.
“推挤”是与团队“共享”分支的过程。 这通常是打开与主分支合并的拉取请求之前的最后一步。
This is a good time to check other guidelines like “linting” of the code, or if all tests are passing.
现在是检查其他准则(如代码的“ lint”)或所有测试是否通过的好时机。
An example for executing another script could be:
执行另一个脚本的示例可能是:
“执行”挂钩 (“Enforce” the hooks)
Another step is to actually enforce those hooks.
另一个步骤是实际执行这些挂钩。
In JavaScript and NPM/Yarn package managers there is a “postinstall” script already built in. It allows for the execution of a script after the installing process. But what exactly should be executed?
在JavaScript和NPM / Yarn程序包管理器中,已经内置了一个“后安装”脚本。它允许在安装过程之后执行脚本。 但是到底应该执行什么呢?
Create your own install script! Like:
创建您自己的安装脚本! 喜欢:
解决一个常见问题 (Fix one common problem)
One issue that kept me guessing for a while was that Git hooks are NOT executable by default. This means that they need to be made executable with
一个让我猜了一段时间的问题是,默认情况下,Git挂钩不可执行。 这意味着需要通过以下方式使它们成为可执行文件:
chmod +x <pathToHo
ok>
chmod +x <pathToHo
ok>
See StackOverflow discussion here.
请参阅此处的 StackOverflow讨论。
谢谢 (Thanks)
I hope that this will help some of you to align the workflow of your development team and make everyone’s lives much easier. :-)
我希望这将有助于你们中的一些人调整开发团队的工作流程,并使每个人的生活变得更加轻松。 :-)
Thanks for reading my article! Feel free to leave any feedback!
感谢您阅读我的文章! 随时留下任何反馈!
Daniel is a software developer, a LL.M. student in business law, and organizer of tech-related events in Vienna. His current personal learning efforts focus on machine learning.
Daniel是LL.M.的软件开发人员。 商法专业学生,维也纳技术相关活动的组织者。 他目前的个人学习重点是机器学习。
Connect on:
连接:
LinkedIn
领英
Github
Github
Medium
中
Twitter
推特
Steemit
Steemit
Hashnode
哈希节点
翻译自: https://www.freecodecamp.org/news/improve-development-workflow-of-your-team-with-githooks-9cda15377c3b/
githooks