@@ -7,40 +7,51 @@ githooks - Hooks used by Git
7
7
8
8
SYNOPSIS
9
9
--------
10
- $GIT_DIR/hooks/*
10
+ $GIT_DIR/hooks/* (or \`git config core.hooksPath`/*)
11
11
12
12
13
13
DESCRIPTION
14
14
-----------
15
15
16
- Hooks are little scripts you can place in `$GIT_DIR/hooks`
17
- directory to trigger action at certain points. When
18
- 'git init' is run, a handful of example hooks are copied into the
19
- `hooks` directory of the new repository, but by default they are
20
- all disabled. To enable a hook, rename it by removing its `.sample`
21
- suffix.
16
+ Hooks are programs you can place in a hooks directory to trigger
17
+ actions at certain points in git's execution. Hooks that don't have
18
+ the executable bit set are ignored.
22
19
23
- NOTE: It is also a requirement for a given hook to be executable.
24
- However - in a freshly initialized repository - the `.sample` files are
25
- executable by default .
20
+ By default the hooks directory is `$GIT_DIR/hooks`, but that can be
21
+ changed via the `core.hooksPath` configuration variable (see
22
+ linkgit:git-config[1]) .
26
23
27
- This document describes the currently defined hooks.
24
+ Before Git invokes a hook, it changes its working directory to either
25
+ the root of the working tree in a non-bare repository, or to the
26
+ $GIT_DIR in a bare repository.
27
+
28
+ Hooks can get their arguments via the environment, command-line
29
+ arguments, and stdin. See the documentation for each hook below for
30
+ details.
31
+
32
+ 'git init' may copy hooks to the new repository, depending on its
33
+ configuration. See the "TEMPLATE DIRECTORY" section in
34
+ linkgit:git-init[1] for details. When the rest of this document refers
35
+ to "default hooks" it's talking about the default template shipped
36
+ with Git.
37
+
38
+ The currently supported hooks are described below.
28
39
29
40
HOOKS
30
41
-----
31
42
32
43
applypatch-msg
33
44
~~~~~~~~~~~~~~
34
45
35
- This hook is invoked by 'git am' script . It takes a single
46
+ This hook is invoked by 'git am'. It takes a single
36
47
parameter, the name of the file that holds the proposed commit
37
- log message. Exiting with non-zero status causes
38
- 'git am' to abort before applying the patch.
48
+ log message. Exiting with a non-zero status causes 'git am' to abort
49
+ before applying the patch.
39
50
40
51
The hook is allowed to edit the message file in place, and can
41
52
be used to normalize the message into some project standard
42
- format (if the project has one) . It can also be used to refuse
43
- the commit after inspecting the message file.
53
+ format. It can also be used to refuse the commit after inspecting
54
+ the message file.
44
55
45
56
The default 'applypatch-msg' hook, when enabled, runs the
46
57
'commit-msg' hook, if the latter is enabled.
@@ -73,10 +84,10 @@ pre-commit
73
84
~~~~~~~~~~
74
85
75
86
This hook is invoked by 'git commit', and can be bypassed
76
- with `--no-verify` option. It takes no parameter , and is
87
+ with the `--no-verify` option. It takes no parameters , and is
77
88
invoked before obtaining the proposed commit log message and
78
- making a commit. Exiting with non-zero status from this script
79
- causes the 'git commit' to abort.
89
+ making a commit. Exiting with a non-zero status from this script
90
+ causes the 'git commit' command to abort before creating a commit .
80
91
81
92
The default 'pre-commit' hook, when enabled, catches introduction
82
93
of lines with trailing whitespaces and aborts the commit when
@@ -115,24 +126,24 @@ commit-msg
115
126
~~~~~~~~~~
116
127
117
128
This hook is invoked by 'git commit', and can be bypassed
118
- with `--no-verify` option. It takes a single parameter, the
129
+ with the `--no-verify` option. It takes a single parameter, the
119
130
name of the file that holds the proposed commit log message.
120
- Exiting with non-zero status causes the 'git commit' to
131
+ Exiting with a non-zero status causes the 'git commit' to
121
132
abort.
122
133
123
- The hook is allowed to edit the message file in place, and can
124
- be used to normalize the message into some project standard
125
- format (if the project has one). It can also be used to refuse
126
- the commit after inspecting the message file.
134
+ The hook is allowed to edit the message file in place, and can be used
135
+ to normalize the message into some project standard format. It
136
+ can also be used to refuse the commit after inspecting the message
137
+ file.
127
138
128
139
The default 'commit-msg' hook, when enabled, detects duplicate
129
140
"Signed-off-by" lines, and aborts the commit if one is found.
130
141
131
142
post-commit
132
143
~~~~~~~~~~~
133
144
134
- This hook is invoked by 'git commit'. It takes no
135
- parameter, and is invoked after a commit is made.
145
+ This hook is invoked by 'git commit'. It takes no parameters, and is
146
+ invoked after a commit is made.
136
147
137
148
This hook is meant primarily for notification, and cannot affect
138
149
the outcome of 'git commit'.
@@ -267,9 +278,11 @@ does not know the entire set of branches, so it would end up
267
278
firing one e-mail per ref when used naively, though. The
268
279
<<post-receive,'post-receive'>> hook is more suited to that.
269
280
270
- Another use suggested on the mailing list is to use this hook to
271
- implement access control which is finer grained than the one
272
- based on filesystem group.
281
+ In an environment that restricts the users' access only to git
282
+ commands over the wire, this hook can be used to implement access
283
+ control without relying on filesystem ownership and group
284
+ membership. See linkgit:git-shell[1] for how you might use the login
285
+ shell to restrict the user's access to only git commands.
273
286
274
287
Both standard output and standard error output are forwarded to
275
288
'git send-pack' on the other end, so you can simply `echo` messages
0 commit comments