吉特仓库管理系统_吉特钩

吉特仓库管理系统

Git, like all good source control systems, allows you to customise the behaviour of the SCM when certain actions occur. For lots of people in lots of projects it’s not vital to use these hooks, but from time-to-time you find yourself repeating the same commands time-and-again. In these scenarios, it is worth looking into setting up a hook for your SCM to run on your behalf.

与所有良好的源代码控制系统一样,Git允许您在发生某些操作时自定义SCM的行为。 对于很多项目中的很多人来说,使用这些挂钩并不是至关重要的,但是有时您会发现自己不时地重复相同的命令。 在这些情况下,值得考虑设置一个SCM挂钩来代表您运行。

Because I’m one of the cool new generation of software monkeys, I use Git as my chosen SCM. One of the great things about Git is that it has a very simple hooks system which is both easy to understand and to use. Allow me to demonstrate.

因为我是很酷的新一代软件猴子之一,所以我选择Git作为我的SCM。 Git的一大优点是它具有非常简单的挂钩系统,既易于理解又易于使用。 请允许我示范。

我的例子,因为这全是我的事 (My Example, Because It’s All About Me)

To demonstrate the usage of Git hooks, I will walk through an example of a Git hook I created for my own use. This will be a Git commit hook: that is to say, an action that runs whenever I commit into a specific repository.

为了演示Git钩子的用法,我将逐步介绍我为自己使用而创建的Git钩子的示例。 这将是一个Git提交钩子:也就是说,每当我提交到特定存储库时,就会运行一个动作。

The repository I’ll be using today is the one in which this website is stored. This website is hosted on Heroku, which means I push and update the website using Git. For this reason, I have a vested interest in minimising the quantity of commands I run on a given update.

我今天将要使用的存储库就是存储该 站的存储库。 该 站托管在Heroku上 ,这意味着我使用Git推送和更新该 站。 由于这个原因,我对最小化在给定更新上运行的命令数量有着既得的兴趣。

My particular issue was pointed out by a shall-remain-anonymous member of the PC Gamer Steam chat room, who noted that the CSS for this blog is served from S3 in an unminified format. This is less than ideal, as it increases both the time it takes to download the four CSS files and the bandwidth costs I pay to supply it to users from S3.

我的特定问题是由PC Gamer Steam聊天室的一名仍然匿名的成员指出的,他指出,此博客CSS是从S3以未最小化格式提供的。 这不是理想的,因为它增加了下载四个CSS文件所需的时间,也增加了我为从S3提供给用户而支付的带宽成本。

Of course, I want to keep the unminified files in source control, because no-one wants to have to edit minified CSS files. That means I need to balance the need to keep hold of the unminified files while supplying the minified ones. This is exactly the kind of situation where a Git hook comes in handy.

准备抓钩 (Prepare For Git Hook)

So let’s consider what we need to do. I already have yuicompressor installed on my machine, so my hook will definitely use that. The way it ought to behave is that, on a commit, Git should minify the full-size CSS files, move them to the directory, and then run to upload them to S3.

因此,让我们考虑一下我们需要做什么。 我的机器上已经安装了yuicompressor ,所以我的钩子肯定会使用它。 它的行为方式是,在提交时,Git应该缩小完整CSS文件,将它们移到目录,然后运行将它们上传到S3。

This requires that I do a few things. Firstly, I need to copy the current static files out of the directory and into a new one, where there will be no name conflict. I called this directory (yeah, not an inventive name, but never mind). I then ‘ed the contents of into . Finally, I added this new folder to the repository and committed the change.

这需要我做一些事情。 首先,我需要将当前的静态文件从目录中复制到新目录中,在该目录中不会出现名称冲突。 我将此目录 (是的,不是发明名称,但没关系)。 然后,我将的内容转换为 。 最后,我将此新文件夹添加到存储库并提交更改。

Next, I write the script I want to run when I commit to the repository. This can actually be any executable file, but because I want to run a series of shell commands I’ve decided to just write a simple Bash script:

接下来,我编写要提交到存储库时要运行的脚本。 这实际上可以是任何可执行文件,但是由于我想运行一系列shell命令,所以我决定只编写一个简单的Bash脚本:

This script should be put in the directory of your git repository. Call it , and run .

该脚本应该放在git仓库的目录中。 将其 ,然后运行 。

This script will then run every time you make a commit into the repository. It will use to minify the CSS files, place them in the static files directory and then upload them to S3.

每当您对存储库进行提交时,该脚本便会运行。 它将使用缩小CSS文件,将它们放置在静态文件目录中,然后将其上传到S3。

整理起来 (Finishing Up)

Of course, this is a very simple look at Git hooks. Git allows you to place hooks on many other parts of the Git use process; in fact, I would be willing to put significant sums of money on the notion that it is Git server hooks that allow Heroku to function the way it does.

当然,这是对Git钩子的非常简单的了解。 Git允许您在Git使用过程的许多其他部分上放置钩子; 实际上,我愿意在Git服务器挂钩上投入大量资金,因为Git服务器挂钩允许Heroku发挥作用。

翻译自: https://www.pybloggers.com/2012/08/git-yer-hooks-in/

吉特仓库管理系统

文章知识点与官方知识档案匹配,可进一步学习相关知识Java技能树首页概览91462 人正在系统学习中 相关资源:吉大软件工程学硕考研专业课.zip_吉林大学考研专业课-专业指导…

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年6月12日
下一篇 2020年6月13日

相关推荐