rebase -i: work on a detached HEAD
[git/dscho.git] / Documentation / hooks.txt
blob58b954759610ca272b72a05db0cd14e2868ff301
1 Hooks used by git
2 =================
4 Hooks are little scripts you can place in `$GIT_DIR/hooks`
5 directory to trigger action at certain points.  When
6 `git-init` is run, a handful example hooks are copied in the
7 `hooks` directory of the new repository, but by default they are
8 all disabled.  To enable a hook, make it executable with `chmod +x`.
10 This document describes the currently defined hooks.
12 applypatch-msg
13 --------------
15 This hook is invoked by `git-am` script.  It takes a single
16 parameter, the name of the file that holds the proposed commit
17 log message.  Exiting with non-zero status causes
18 `git-am` to abort before applying the patch.
20 The hook is allowed to edit the message file in place, and can
21 be used to normalize the message into some project standard
22 format (if the project has one). It can also be used to refuse
23 the commit after inspecting the message file.
25 The default 'applypatch-msg' hook, when enabled, runs the
26 'commit-msg' hook, if the latter is enabled.
28 pre-applypatch
29 --------------
31 This hook is invoked by `git-am`.  It takes no parameter,
32 and is invoked after the patch is applied, but before a commit
33 is made.  Exiting with non-zero status causes the working tree
34 after application of the patch not committed.
36 It can be used to inspect the current working tree and refuse to
37 make a commit if it does not pass certain test.
39 The default 'pre-applypatch' hook, when enabled, runs the
40 'pre-commit' hook, if the latter is enabled.
42 post-applypatch
43 ---------------
45 This hook is invoked by `git-am`.  It takes no parameter,
46 and is invoked after the patch is applied and a commit is made.
48 This hook is meant primarily for notification, and cannot affect
49 the outcome of `git-am`.
51 pre-commit
52 ----------
54 This hook is invoked by `git-commit`, and can be bypassed
55 with `\--no-verify` option.  It takes no parameter, and is
56 invoked before obtaining the proposed commit log message and
57 making a commit.  Exiting with non-zero status from this script
58 causes the `git-commit` to abort.
60 The default 'pre-commit' hook, when enabled, catches introduction
61 of lines with trailing whitespaces and aborts the commit when
62 such a line is found.
64 commit-msg
65 ----------
67 This hook is invoked by `git-commit`, and can be bypassed
68 with `\--no-verify` option.  It takes a single parameter, the
69 name of the file that holds the proposed commit log message.
70 Exiting with non-zero status causes the `git-commit` to
71 abort.
73 The hook is allowed to edit the message file in place, and can
74 be used to normalize the message into some project standard
75 format (if the project has one). It can also be used to refuse
76 the commit after inspecting the message file.
78 The default 'commit-msg' hook, when enabled, detects duplicate
79 "Signed-off-by" lines, and aborts the commit if one is found.
81 post-commit
82 -----------
84 This hook is invoked by `git-commit`.  It takes no
85 parameter, and is invoked after a commit is made.
87 This hook is meant primarily for notification, and cannot affect
88 the outcome of `git-commit`.
90 post-merge
91 -----------
93 This hook is invoked by `git-merge`, which happens when a `git pull`
94 is done on a local repository.  The hook takes a single parameter, a status
95 flag specifying whether or not the merge being done was a squash merge.
96 This hook cannot affect the outcome of `git-merge`.
98 This hook can be used in conjunction with a corresponding pre-commit hook to
99 save and restore any form of metadata associated with the working tree
100 (eg: permissions/ownership, ACLS, etc).  See contrib/hooks/setgitperms.perl
101 for an example of how to do this.
103 [[pre-receive]]
104 pre-receive
105 -----------
107 This hook is invoked by `git-receive-pack` on the remote repository,
108 which happens when a `git push` is done on a local repository.
109 Just before starting to update refs on the remote repository, the
110 pre-receive hook is invoked.  Its exit status determines the success
111 or failure of the update.
113 This hook executes once for the receive operation. It takes no
114 arguments, but for each ref to be updated it receives on standard
115 input a line of the format:
117   <old-value> SP <new-value> SP <ref-name> LF
119 where `<old-value>` is the old object name stored in the ref,
120 `<new-value>` is the new object name to be stored in the ref and
121 `<ref-name>` is the full name of the ref.
122 When creating a new ref, `<old-value>` is 40 `0`.
124 If the hook exits with non-zero status, none of the refs will be
125 updated. If the hook exits with zero, updating of individual refs can
126 still be prevented by the <<update,'update'>> hook.
128 Both standard output and standard error output are forwarded to
129 `git-send-pack` on the other end, so you can simply `echo` messages
130 for the user.
132 [[update]]
133 update
134 ------
136 This hook is invoked by `git-receive-pack` on the remote repository,
137 which happens when a `git push` is done on a local repository.
138 Just before updating the ref on the remote repository, the update hook
139 is invoked.  Its exit status determines the success or failure of
140 the ref update.
142 The hook executes once for each ref to be updated, and takes
143 three parameters:
145  - the name of the ref being updated,
146  - the old object name stored in the ref,
147  - and the new objectname to be stored in the ref.
149 A zero exit from the update hook allows the ref to be updated.
150 Exiting with a non-zero status prevents `git-receive-pack`
151 from updating that ref.
153 This hook can be used to prevent 'forced' update on certain refs by
154 making sure that the object name is a commit object that is a
155 descendant of the commit object named by the old object name.
156 That is, to enforce a "fast forward only" policy.
158 It could also be used to log the old..new status.  However, it
159 does not know the entire set of branches, so it would end up
160 firing one e-mail per ref when used naively, though.  The
161 <<post-receive,'post-receive'>> hook is more suited to that.
163 Another use suggested on the mailing list is to use this hook to
164 implement access control which is finer grained than the one
165 based on filesystem group.
167 Both standard output and standard error output are forwarded to
168 `git-send-pack` on the other end, so you can simply `echo` messages
169 for the user.
171 The default 'update' hook, when enabled--and with
172 `hooks.allowunannotated` config option turned on--prevents
173 unannotated tags to be pushed.
175 [[post-receive]]
176 post-receive
177 ------------
179 This hook is invoked by `git-receive-pack` on the remote repository,
180 which happens when a `git push` is done on a local repository.
181 It executes on the remote repository once after all the refs have
182 been updated.
184 This hook executes once for the receive operation.  It takes no
185 arguments, but gets the same information as the
186 <<pre-receive,'pre-receive'>>
187 hook does on its standard input.
189 This hook does not affect the outcome of `git-receive-pack`, as it
190 is called after the real work is done.
192 This supersedes the <<post-update,'post-update'>> hook in that it gets
193 both old and new values of all the refs in addition to their
194 names.
196 Both standard output and standard error output are forwarded to
197 `git-send-pack` on the other end, so you can simply `echo` messages
198 for the user.
200 The default 'post-receive' hook is empty, but there is
201 a sample script `post-receive-email` provided in the `contrib/hooks`
202 directory in git distribution, which implements sending commit
203 emails.
205 [[post-update]]
206 post-update
207 -----------
209 This hook is invoked by `git-receive-pack` on the remote repository,
210 which happens when a `git push` is done on a local repository.
211 It executes on the remote repository once after all the refs have
212 been updated.
214 It takes a variable number of parameters, each of which is the
215 name of ref that was actually updated.
217 This hook is meant primarily for notification, and cannot affect
218 the outcome of `git-receive-pack`.
220 The 'post-update' hook can tell what are the heads that were pushed,
221 but it does not know what their original and updated values are,
222 so it is a poor place to do log old..new. The
223 <<post-receive,'post-receive'>> hook does get both original and
224 updated values of the refs. You might consider it instead if you need
225 them.
227 When enabled, the default 'post-update' hook runs
228 `git-update-server-info` to keep the information used by dumb
229 transports (e.g., HTTP) up-to-date.  If you are publishing
230 a git repository that is accessible via HTTP, you should
231 probably enable this hook.
233 Both standard output and standard error output are forwarded to
234 `git-send-pack` on the other end, so you can simply `echo` messages
235 for the user.