Three minutes to teach you to learn git (17)-Hooks

Source: Internet
Author: User

Git can customize hooks that can be executed under certain circumstances, divided into client-side hooks and server-side hooks. Client-side hooks are triggered by operation, such as Commit,merge, server-side hooks are triggered by network actions, such as pushed commits.


So where does the hook go?

Under the. git/hooks/folder. When you init a warehouse, there are some examples of hooks below, ending with. Sample.


Then when the hook is executed, git pre-defines the trigger timing:

Clientside Hooks:

1 Pre-commit, when performing a commit action, the hook is executed first, you can use this hook to do some checks, such as code style check, or run the test first.

2 prepare-commit-msg, this hook is triggered when a commit is required to enter a message, so you can use this hook to customize your default message information.

3 Commit-msg, when the user input a commit message is triggered, you can use this hook to verify the message information, such as whether it complies with the provisions, there is no CR.

4 Post-commit, when commit is triggered, you can send notification with this hook.

5 Pre-rebase, Rebase will be triggered before, you can use this hook to reject all the already push commits for rebase operation.

6 Post-merge, this hook will be triggered when the merge succeeds.

7 Pre-push, when push, remote refs is updated, but is triggered before all objects are transmitted.

8 PRE-AUTO-GC, which is triggered before Git GC--auto executes. It's nice to do some verification or backup before garbage collection.


ServerSide Hooks:

1 pre-receive, which is executed before the push action is received.

2 Update is also executed before the push action is received, but it is possible to be executed multiple times, each branch once.

3 Post-receive, when the push action is completed, it will be triggered, you can use this hook to push notification, such as e-mail, notify the continuous build server and so on.


Remember that all hooks are supposed to be executed.

chmod u+x Your_hook

So you can use shell scripts, Perl,python and so on to write hooks.


Original: http://blog.csdn.net/hongchangfirst/article/details/46693237

Author: Hongchangfirst

Hongchangfirst's homepage: http://blog.csdn.net/hongchangfirst




Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Three minutes to teach you to learn git (17)-Hooks

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.