blob: 2c03526ef34d2642f7d76d2ed3858d3c3d166b7f [file] [log] [blame]
Junio C Hamano2fbcd212008-05-14 22:26:071<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4<head>
5<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6<meta name="generator" content="AsciiDoc 7.0.2" />
7<style type="text/css">
8/* Debug borders */
9p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
10/*
11 border: 1px solid red;
12*/
13}
14
15body {
16 margin: 1em 5% 1em 5%;
17}
18
19a { color: blue; }
20a:visited { color: fuchsia; }
21
22em {
23 font-style: italic;
24}
25
26strong {
27 font-weight: bold;
28}
29
30tt {
31 color: navy;
32}
33
34h1, h2, h3, h4, h5, h6 {
35 color: #527bbd;
36 font-family: sans-serif;
37 margin-top: 1.2em;
38 margin-bottom: 0.5em;
39 line-height: 1.3;
40}
41
42h1 {
43 border-bottom: 2px solid silver;
44}
45h2 {
46 border-bottom: 2px solid silver;
47 padding-top: 0.5em;
48}
49
50div.sectionbody {
51 font-family: serif;
52 margin-left: 0;
53}
54
55hr {
56 border: 1px solid silver;
57}
58
59p {
60 margin-top: 0.5em;
61 margin-bottom: 0.5em;
62}
63
64pre {
65 padding: 0;
66 margin: 0;
67}
68
69span#author {
70 color: #527bbd;
71 font-family: sans-serif;
72 font-weight: bold;
73 font-size: 1.2em;
74}
75span#email {
76}
77span#revision {
78 font-family: sans-serif;
79}
80
81div#footer {
82 font-family: sans-serif;
83 font-size: small;
84 border-top: 2px solid silver;
85 padding-top: 0.5em;
86 margin-top: 4.0em;
87}
88div#footer-text {
89 float: left;
90 padding-bottom: 0.5em;
91}
92div#footer-badges {
93 float: right;
94 padding-bottom: 0.5em;
95}
96
97div#preamble,
98div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
99div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
100div.admonitionblock {
101 margin-right: 10%;
102 margin-top: 1.5em;
103 margin-bottom: 1.5em;
104}
105div.admonitionblock {
106 margin-top: 2.5em;
107 margin-bottom: 2.5em;
108}
109
110div.content { /* Block element content. */
111 padding: 0;
112}
113
114/* Block element titles. */
115div.title, caption.title {
116 font-family: sans-serif;
117 font-weight: bold;
118 text-align: left;
119 margin-top: 1.0em;
120 margin-bottom: 0.5em;
121}
122div.title + * {
123 margin-top: 0;
124}
125
126td div.title:first-child {
127 margin-top: 0.0em;
128}
129div.content div.title:first-child {
130 margin-top: 0.0em;
131}
132div.content + div.title {
133 margin-top: 0.0em;
134}
135
136div.sidebarblock > div.content {
137 background: #ffffee;
138 border: 1px solid silver;
139 padding: 0.5em;
140}
141
142div.listingblock > div.content {
143 border: 1px solid silver;
144 background: #f4f4f4;
145 padding: 0.5em;
146}
147
148div.quoteblock > div.content {
149 padding-left: 2.0em;
150}
151div.quoteblock .attribution {
152 text-align: right;
153}
154
155div.admonitionblock .icon {
156 vertical-align: top;
157 font-size: 1.1em;
158 font-weight: bold;
159 text-decoration: underline;
160 color: #527bbd;
161 padding-right: 0.5em;
162}
163div.admonitionblock td.content {
164 padding-left: 0.5em;
165 border-left: 2px solid silver;
166}
167
168div.exampleblock > div.content {
169 border-left: 2px solid silver;
170 padding: 0.5em;
171}
172
173div.verseblock div.content {
174 white-space: pre;
175}
176
177div.imageblock div.content { padding-left: 0; }
178div.imageblock img { border: 1px solid silver; }
179span.image img { border-style: none; }
180
181dl {
182 margin-top: 0.8em;
183 margin-bottom: 0.8em;
184}
185dt {
186 margin-top: 0.5em;
187 margin-bottom: 0;
188 font-style: italic;
189}
190dd > *:first-child {
191 margin-top: 0;
192}
193
194ul, ol {
195 list-style-position: outside;
196}
197ol.olist2 {
198 list-style-type: lower-alpha;
199}
200
201div.tableblock > table {
202 border-color: #527bbd;
203 border-width: 3px;
204}
205thead {
206 font-family: sans-serif;
207 font-weight: bold;
208}
209tfoot {
210 font-weight: bold;
211}
212
213div.hlist {
214 margin-top: 0.8em;
215 margin-bottom: 0.8em;
216}
217td.hlist1 {
218 vertical-align: top;
219 font-style: italic;
220 padding-right: 0.8em;
221}
222td.hlist2 {
223 vertical-align: top;
224}
225
226@media print {
227 div#footer-badges { display: none; }
228}
229include::./stylesheets/xhtml11-manpage.css[]
230/* Workarounds for IE6's broken and incomplete CSS2. */
231
232div.sidebar-content {
233 background: #ffffee;
234 border: 1px solid silver;
235 padding: 0.5em;
236}
237div.sidebar-title, div.image-title {
238 font-family: sans-serif;
239 font-weight: bold;
240 margin-top: 0.0em;
241 margin-bottom: 0.5em;
242}
243
244div.listingblock div.content {
245 border: 1px solid silver;
246 background: #f4f4f4;
247 padding: 0.5em;
248}
249
250div.quoteblock-content {
251 padding-left: 2.0em;
252}
253
254div.exampleblock-content {
255 border-left: 2px solid silver;
256 padding-left: 0.5em;
257}
258</style>
259<title>githooks(5)</title>
260</head>
261<body>
262<div id="header">
263<h1>
264githooks(5) Manual Page
265</h1>
266<h2>NAME</h2>
267<div class="sectionbody">
268<p>githooks -
269 Hooks used by git
270</p>
271</div>
272</div>
273<h2>SYNOPSIS</h2>
274<div class="sectionbody">
275<p>$GIT_DIR/hooks/*</p>
276</div>
277<h2>DESCRIPTION</h2>
278<div class="sectionbody">
279<p>Hooks are little scripts you can place in <tt>$GIT_DIR/hooks</tt>
280directory to trigger action at certain points. When
281<tt>git-init</tt> is run, a handful example hooks are copied in the
282<tt>hooks</tt> directory of the new repository, but by default they are
283all disabled. To enable a hook, make it executable with <tt>chmod +x</tt>.</p>
284<p>This document describes the currently defined hooks.</p>
285</div>
286<h2>applypatch-msg</h2>
287<div class="sectionbody">
288<p>This hook is invoked by <tt>git-am</tt> script. It takes a single
289parameter, the name of the file that holds the proposed commit
290log message. Exiting with non-zero status causes
291<tt>git-am</tt> to abort before applying the patch.</p>
292<p>The hook is allowed to edit the message file in place, and can
293be used to normalize the message into some project standard
294format (if the project has one). It can also be used to refuse
295the commit after inspecting the message file.</p>
296<p>The default <em>applypatch-msg</em> hook, when enabled, runs the
297<em>commit-msg</em> hook, if the latter is enabled.</p>
298</div>
299<h2>pre-applypatch</h2>
300<div class="sectionbody">
301<p>This hook is invoked by <tt>git-am</tt>. It takes no parameter, and is
302invoked after the patch is applied, but before a commit is made.</p>
303<p>If it exits with non-zero status, then the working tree will not be
304committed after applying the patch.</p>
305<p>It can be used to inspect the current working tree and refuse to
306make a commit if it does not pass certain test.</p>
307<p>The default <em>pre-applypatch</em> hook, when enabled, runs the
308<em>pre-commit</em> hook, if the latter is enabled.</p>
309</div>
310<h2>post-applypatch</h2>
311<div class="sectionbody">
312<p>This hook is invoked by <tt>git-am</tt>. It takes no parameter,
313and is invoked after the patch is applied and a commit is made.</p>
314<p>This hook is meant primarily for notification, and cannot affect
315the outcome of <tt>git-am</tt>.</p>
316</div>
317<h2>pre-commit</h2>
318<div class="sectionbody">
319<p>This hook is invoked by <tt>git-commit</tt>, and can be bypassed
320with <tt>--no-verify</tt> option. It takes no parameter, and is
321invoked before obtaining the proposed commit log message and
322making a commit. Exiting with non-zero status from this script
323causes the <tt>git-commit</tt> to abort.</p>
324<p>The default <em>pre-commit</em> hook, when enabled, catches introduction
325of lines with trailing whitespaces and aborts the commit when
326such a line is found.</p>
327<p>All the <tt>git-commit</tt> hooks are invoked with the environment
328variable <tt>GIT_EDITOR=:</tt> if the command will not bring up an editor
329to modify the commit message.</p>
330</div>
331<h2>prepare-commit-msg</h2>
332<div class="sectionbody">
333<p>This hook is invoked by <tt>git-commit</tt> right after preparing the
334default log message, and before the editor is started.</p>
335<p>It takes one to three parameters. The first is the name of the file
336that the commit log message. The second is the source of the commit
337message, and can be: <tt>message</tt> (if a <tt>\-m</tt> or <tt>\-F</tt> option was
338given); <tt>template</tt> (if a <tt>\-t</tt> option was given or the
339configuration option <tt>commit.template</tt> is set); <tt>merge</tt> (if the
340commit is a merge or a <tt>.git/MERGE_MSG</tt> file exists); <tt>squash</tt>
341(if a <tt>.git/SQUASH_MSG</tt> file exists); or <tt>commit</tt>, followed by
342a commit SHA1 (if a <tt>\-c</tt>, <tt>\-C</tt> or <tt>--amend</tt> option was given).</p>
343<p>If the exit status is non-zero, <tt>git-commit</tt> will abort.</p>
344<p>The purpose of the hook is to edit the message file in place, and
345it is not suppressed by the <tt>--no-verify</tt> option. A non-zero exit
346means a failure of the hook and aborts the commit. It should not
347be used as replacement for pre-commit hook.</p>
348<p>The sample <tt>prepare-commit-msg</tt> hook that comes with git comments
349out the <tt>Conflicts:</tt> part of a merge's commit message.</p>
350</div>
351<h2>commit-msg</h2>
352<div class="sectionbody">
353<p>This hook is invoked by <tt>git-commit</tt>, and can be bypassed
354with <tt>--no-verify</tt> option. It takes a single parameter, the
355name of the file that holds the proposed commit log message.
356Exiting with non-zero status causes the <tt>git-commit</tt> to
357abort.</p>
358<p>The hook is allowed to edit the message file in place, and can
359be used to normalize the message into some project standard
360format (if the project has one). It can also be used to refuse
361the commit after inspecting the message file.</p>
362<p>The default <em>commit-msg</em> hook, when enabled, detects duplicate
363"Signed-off-by" lines, and aborts the commit if one is found.</p>
364</div>
365<h2>post-commit</h2>
366<div class="sectionbody">
367<p>This hook is invoked by <tt>git-commit</tt>. It takes no
368parameter, and is invoked after a commit is made.</p>
369<p>This hook is meant primarily for notification, and cannot affect
370the outcome of <tt>git-commit</tt>.</p>
371</div>
372<h2>post-checkout</h2>
373<div class="sectionbody">
374<p>This hook is invoked when a <tt>git-checkout</tt> is run after having updated the
375worktree. The hook is given three parameters: the ref of the previous HEAD,
376the ref of the new HEAD (which may or may not have changed), and a flag
377indicating whether the checkout was a branch checkout (changing branches,
378flag=1) or a file checkout (retrieving a file from the index, flag=0).
379This hook cannot affect the outcome of <tt>git-checkout</tt>.</p>
380<p>This hook can be used to perform repository validity checks, auto-display
381differences from the previous HEAD if different, or set working dir metadata
382properties.</p>
383</div>
384<h2>post-merge</h2>
385<div class="sectionbody">
386<p>This hook is invoked by <tt>git-merge</tt>, which happens when a <tt>git pull</tt>
387is done on a local repository. The hook takes a single parameter, a status
388flag specifying whether or not the merge being done was a squash merge.
389This hook cannot affect the outcome of <tt>git-merge</tt> and is not executed,
390if the merge failed due to conflicts.</p>
391<p>This hook can be used in conjunction with a corresponding pre-commit hook to
392save and restore any form of metadata associated with the working tree
393(eg: permissions/ownership, ACLS, etc). See contrib/hooks/setgitperms.perl
394for an example of how to do this.</p>
395</div>
396<h2><a id="pre-receive"></a>pre-receive</h2>
397<div class="sectionbody">
398<p>This hook is invoked by <tt>git-receive-pack</tt> on the remote repository,
399which happens when a <tt>git push</tt> is done on a local repository.
400Just before starting to update refs on the remote repository, the
401pre-receive hook is invoked. Its exit status determines the success
402or failure of the update.</p>
403<p>This hook executes once for the receive operation. It takes no
404arguments, but for each ref to be updated it receives on standard
405input a line of the format:</p>
406<div class="literalblock">
407<div class="content">
408<pre><tt>&lt;old-value&gt; SP &lt;new-value&gt; SP &lt;ref-name&gt; LF</tt></pre>
409</div></div>
410<p>where <tt>&lt;old-value&gt;</tt> is the old object name stored in the ref,
411<tt>&lt;new-value&gt;</tt> is the new object name to be stored in the ref and
412<tt>&lt;ref-name&gt;</tt> is the full name of the ref.
413When creating a new ref, <tt>&lt;old-value&gt;</tt> is 40 <tt>0</tt>.</p>
414<p>If the hook exits with non-zero status, none of the refs will be
415updated. If the hook exits with zero, updating of individual refs can
416still be prevented by the <a href="#update"><em>update</em></a> hook.</p>
417<p>Both standard output and standard error output are forwarded to
418<tt>git-send-pack</tt> on the other end, so you can simply <tt>echo</tt> messages
419for the user.</p>
420</div>
421<h2><a id="update"></a>update</h2>
422<div class="sectionbody">
423<p>This hook is invoked by <tt>git-receive-pack</tt> on the remote repository,
424which happens when a <tt>git push</tt> is done on a local repository.
425Just before updating the ref on the remote repository, the update hook
426is invoked. Its exit status determines the success or failure of
427the ref update.</p>
428<p>The hook executes once for each ref to be updated, and takes
429three parameters:</p>
430<ul>
431<li>
432<p>
433the name of the ref being updated,
434</p>
435</li>
436<li>
437<p>
438the old object name stored in the ref,
439</p>
440</li>
441<li>
442<p>
443and the new objectname to be stored in the ref.
444</p>
445</li>
446</ul>
447<p>A zero exit from the update hook allows the ref to be updated.
448Exiting with a non-zero status prevents <tt>git-receive-pack</tt>
449from updating that ref.</p>
450<p>This hook can be used to prevent <em>forced</em> update on certain refs by
451making sure that the object name is a commit object that is a
452descendant of the commit object named by the old object name.
453That is, to enforce a "fast forward only" policy.</p>
454<p>It could also be used to log the old..new status. However, it
455does not know the entire set of branches, so it would end up
456firing one e-mail per ref when used naively, though. The
457<a href="#post-receive"><em>post-receive</em></a> hook is more suited to that.</p>
458<p>Another use suggested on the mailing list is to use this hook to
459implement access control which is finer grained than the one
460based on filesystem group.</p>
461<p>Both standard output and standard error output are forwarded to
462<tt>git-send-pack</tt> on the other end, so you can simply <tt>echo</tt> messages
463for the user.</p>
464<p>The default <em>update</em> hook, when enabled--and with
465<tt>hooks.allowunannotated</tt> config option turned on--prevents
466unannotated tags to be pushed.</p>
467</div>
468<h2><a id="post-receive"></a>post-receive</h2>
469<div class="sectionbody">
470<p>This hook is invoked by <tt>git-receive-pack</tt> on the remote repository,
471which happens when a <tt>git push</tt> is done on a local repository.
472It executes on the remote repository once after all the refs have
473been updated.</p>
474<p>This hook executes once for the receive operation. It takes no
475arguments, but gets the same information as the
476<a href="#pre-receive"><em>pre-receive</em></a>
477hook does on its standard input.</p>
478<p>This hook does not affect the outcome of <tt>git-receive-pack</tt>, as it
479is called after the real work is done.</p>
480<p>This supersedes the <a href="#post-update"><em>post-update</em></a> hook in that it gets
481both old and new values of all the refs in addition to their
482names.</p>
483<p>Both standard output and standard error output are forwarded to
484<tt>git-send-pack</tt> on the other end, so you can simply <tt>echo</tt> messages
485for the user.</p>
486<p>The default <em>post-receive</em> hook is empty, but there is
487a sample script <tt>post-receive-email</tt> provided in the <tt>contrib/hooks</tt>
488directory in git distribution, which implements sending commit
489emails.</p>
490</div>
491<h2><a id="post-update"></a>post-update</h2>
492<div class="sectionbody">
493<p>This hook is invoked by <tt>git-receive-pack</tt> on the remote repository,
494which happens when a <tt>git push</tt> is done on a local repository.
495It executes on the remote repository once after all the refs have
496been updated.</p>
497<p>It takes a variable number of parameters, each of which is the
498name of ref that was actually updated.</p>
499<p>This hook is meant primarily for notification, and cannot affect
500the outcome of <tt>git-receive-pack</tt>.</p>
501<p>The <em>post-update</em> hook can tell what are the heads that were pushed,
502but it does not know what their original and updated values are,
503so it is a poor place to do log old..new. The
504<a href="#post-receive"><em>post-receive</em></a> hook does get both original and
505updated values of the refs. You might consider it instead if you need
506them.</p>
507<p>When enabled, the default <em>post-update</em> hook runs
508<tt>git-update-server-info</tt> to keep the information used by dumb
509transports (e.g., HTTP) up-to-date. If you are publishing
510a git repository that is accessible via HTTP, you should
511probably enable this hook.</p>
512<p>Both standard output and standard error output are forwarded to
513<tt>git-send-pack</tt> on the other end, so you can simply <tt>echo</tt> messages
514for the user.</p>
515</div>
516<h2>pre-auto-gc</h2>
517<div class="sectionbody">
518<p>This hook is invoked by <tt>git-gc --auto</tt>. It takes no parameter, and
519exiting with non-zero status from this script causes the <tt>git-gc --auto</tt>
520to abort.</p>
521</div>
522<h2>GIT</h2>
523<div class="sectionbody">
524<p>Part of the <a href="git.html">git(7)</a> suite</p>
525</div>
526<div id="footer">
527<div id="footer-text">
528Last updated 14-May-2008 22:24:43 UTC
529</div>
530</div>
531</body>
532</html>