Documentation / githooks.txton commit Merge branch 'jc/perl-cat-blob' into maint-1.8.1 (a134a60)
   1githooks(5)
   2===========
   3
   4NAME
   5----
   6githooks - Hooks used by git
   7
   8SYNOPSIS
   9--------
  10$GIT_DIR/hooks/*
  11
  12
  13DESCRIPTION
  14-----------
  15
  16Hooks are little scripts you can place in `$GIT_DIR/hooks`
  17directory 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
  20all disabled.  To enable a hook, rename it by removing its `.sample`
  21suffix.
  22
  23NOTE: It is also a requirement for a given hook to be executable.
  24However - in a freshly initialized repository - the `.sample` files are
  25executable by default.
  26
  27This document describes the currently defined hooks.
  28
  29HOOKS
  30-----
  31
  32applypatch-msg
  33~~~~~~~~~~~~~~
  34
  35This hook is invoked by 'git am' script.  It takes a single
  36parameter, the name of the file that holds the proposed commit
  37log message.  Exiting with non-zero status causes
  38'git am' to abort before applying the patch.
  39
  40The hook is allowed to edit the message file in place, and can
  41be used to normalize the message into some project standard
  42format (if the project has one). It can also be used to refuse
  43the commit after inspecting the message file.
  44
  45The default 'applypatch-msg' hook, when enabled, runs the
  46'commit-msg' hook, if the latter is enabled.
  47
  48pre-applypatch
  49~~~~~~~~~~~~~~
  50
  51This hook is invoked by 'git am'.  It takes no parameter, and is
  52invoked after the patch is applied, but before a commit is made.
  53
  54If it exits with non-zero status, then the working tree will not be
  55committed after applying the patch.
  56
  57It can be used to inspect the current working tree and refuse to
  58make a commit if it does not pass certain test.
  59
  60The default 'pre-applypatch' hook, when enabled, runs the
  61'pre-commit' hook, if the latter is enabled.
  62
  63post-applypatch
  64~~~~~~~~~~~~~~~
  65
  66This hook is invoked by 'git am'.  It takes no parameter,
  67and is invoked after the patch is applied and a commit is made.
  68
  69This hook is meant primarily for notification, and cannot affect
  70the outcome of 'git am'.
  71
  72pre-commit
  73~~~~~~~~~~
  74
  75This hook is invoked by 'git commit', and can be bypassed
  76with `--no-verify` option.  It takes no parameter, and is
  77invoked before obtaining the proposed commit log message and
  78making a commit.  Exiting with non-zero status from this script
  79causes the 'git commit' to abort.
  80
  81The default 'pre-commit' hook, when enabled, catches introduction
  82of lines with trailing whitespaces and aborts the commit when
  83such a line is found.
  84
  85All the 'git commit' hooks are invoked with the environment
  86variable `GIT_EDITOR=:` if the command will not bring up an editor
  87to modify the commit message.
  88
  89prepare-commit-msg
  90~~~~~~~~~~~~~~~~~~
  91
  92This hook is invoked by 'git commit' right after preparing the
  93default log message, and before the editor is started.
  94
  95It takes one to three parameters.  The first is the name of the file
  96that contains the commit log message.  The second is the source of the commit
  97message, and can be: `message` (if a `-m` or `-F` option was
  98given); `template` (if a `-t` option was given or the
  99configuration option `commit.template` is set); `merge` (if the
 100commit is a merge or a `.git/MERGE_MSG` file exists); `squash`
 101(if a `.git/SQUASH_MSG` file exists); or `commit`, followed by
 102a commit SHA1 (if a `-c`, `-C` or `--amend` option was given).
 103
 104If the exit status is non-zero, 'git commit' will abort.
 105
 106The purpose of the hook is to edit the message file in place, and
 107it is not suppressed by the `--no-verify` option.  A non-zero exit
 108means a failure of the hook and aborts the commit.  It should not
 109be used as replacement for pre-commit hook.
 110
 111The sample `prepare-commit-msg` hook that comes with git comments
 112out the `Conflicts:` part of a merge's commit message.
 113
 114commit-msg
 115~~~~~~~~~~
 116
 117This hook is invoked by 'git commit', and can be bypassed
 118with `--no-verify` option.  It takes a single parameter, the
 119name of the file that holds the proposed commit log message.
 120Exiting with non-zero status causes the 'git commit' to
 121abort.
 122
 123The hook is allowed to edit the message file in place, and can
 124be used to normalize the message into some project standard
 125format (if the project has one). It can also be used to refuse
 126the commit after inspecting the message file.
 127
 128The default 'commit-msg' hook, when enabled, detects duplicate
 129"Signed-off-by" lines, and aborts the commit if one is found.
 130
 131post-commit
 132~~~~~~~~~~~
 133
 134This hook is invoked by 'git commit'.  It takes no
 135parameter, and is invoked after a commit is made.
 136
 137This hook is meant primarily for notification, and cannot affect
 138the outcome of 'git commit'.
 139
 140pre-rebase
 141~~~~~~~~~~
 142
 143This hook is called by 'git rebase' and can be used to prevent a
 144branch from getting rebased.  The hook may be called with one or
 145two parameters.  The first parameter is the upstream from which
 146the series was forked.  The second parameter is the branch being
 147rebased, and is not set when rebasing the current branch.
 148
 149post-checkout
 150~~~~~~~~~~~~~
 151
 152This hook is invoked when a 'git checkout' is run after having updated the
 153worktree.  The hook is given three parameters: the ref of the previous HEAD,
 154the ref of the new HEAD (which may or may not have changed), and a flag
 155indicating whether the checkout was a branch checkout (changing branches,
 156flag=1) or a file checkout (retrieving a file from the index, flag=0).
 157This hook cannot affect the outcome of 'git checkout'.
 158
 159It is also run after 'git clone', unless the --no-checkout (-n) option is
 160used. The first parameter given to the hook is the null-ref, the second the
 161ref of the new HEAD and the flag is always 1.
 162
 163This hook can be used to perform repository validity checks, auto-display
 164differences from the previous HEAD if different, or set working dir metadata
 165properties.
 166
 167post-merge
 168~~~~~~~~~~
 169
 170This hook is invoked by 'git merge', which happens when a 'git pull'
 171is done on a local repository.  The hook takes a single parameter, a status
 172flag specifying whether or not the merge being done was a squash merge.
 173This hook cannot affect the outcome of 'git merge' and is not executed,
 174if the merge failed due to conflicts.
 175
 176This hook can be used in conjunction with a corresponding pre-commit hook to
 177save and restore any form of metadata associated with the working tree
 178(eg: permissions/ownership, ACLS, etc).  See contrib/hooks/setgitperms.perl
 179for an example of how to do this.
 180
 181[[pre-receive]]
 182pre-receive
 183~~~~~~~~~~~
 184
 185This hook is invoked by 'git-receive-pack' on the remote repository,
 186which happens when a 'git push' is done on a local repository.
 187Just before starting to update refs on the remote repository, the
 188pre-receive hook is invoked.  Its exit status determines the success
 189or failure of the update.
 190
 191This hook executes once for the receive operation. It takes no
 192arguments, but for each ref to be updated it receives on standard
 193input a line of the format:
 194
 195  <old-value> SP <new-value> SP <ref-name> LF
 196
 197where `<old-value>` is the old object name stored in the ref,
 198`<new-value>` is the new object name to be stored in the ref and
 199`<ref-name>` is the full name of the ref.
 200When creating a new ref, `<old-value>` is 40 `0`.
 201
 202If the hook exits with non-zero status, none of the refs will be
 203updated. If the hook exits with zero, updating of individual refs can
 204still be prevented by the <<update,'update'>> hook.
 205
 206Both standard output and standard error output are forwarded to
 207'git send-pack' on the other end, so you can simply `echo` messages
 208for the user.
 209
 210[[update]]
 211update
 212~~~~~~
 213
 214This hook is invoked by 'git-receive-pack' on the remote repository,
 215which happens when a 'git push' is done on a local repository.
 216Just before updating the ref on the remote repository, the update hook
 217is invoked.  Its exit status determines the success or failure of
 218the ref update.
 219
 220The hook executes once for each ref to be updated, and takes
 221three parameters:
 222
 223 - the name of the ref being updated,
 224 - the old object name stored in the ref,
 225 - and the new objectname to be stored in the ref.
 226
 227A zero exit from the update hook allows the ref to be updated.
 228Exiting with a non-zero status prevents 'git-receive-pack'
 229from updating that ref.
 230
 231This hook can be used to prevent 'forced' update on certain refs by
 232making sure that the object name is a commit object that is a
 233descendant of the commit object named by the old object name.
 234That is, to enforce a "fast-forward only" policy.
 235
 236It could also be used to log the old..new status.  However, it
 237does not know the entire set of branches, so it would end up
 238firing one e-mail per ref when used naively, though.  The
 239<<post-receive,'post-receive'>> hook is more suited to that.
 240
 241Another use suggested on the mailing list is to use this hook to
 242implement access control which is finer grained than the one
 243based on filesystem group.
 244
 245Both standard output and standard error output are forwarded to
 246'git send-pack' on the other end, so you can simply `echo` messages
 247for the user.
 248
 249The default 'update' hook, when enabled--and with
 250`hooks.allowunannotated` config option unset or set to false--prevents
 251unannotated tags to be pushed.
 252
 253[[post-receive]]
 254post-receive
 255~~~~~~~~~~~~
 256
 257This hook is invoked by 'git-receive-pack' on the remote repository,
 258which happens when a 'git push' is done on a local repository.
 259It executes on the remote repository once after all the refs have
 260been updated.
 261
 262This hook executes once for the receive operation.  It takes no
 263arguments, but gets the same information as the
 264<<pre-receive,'pre-receive'>>
 265hook does on its standard input.
 266
 267This hook does not affect the outcome of 'git-receive-pack', as it
 268is called after the real work is done.
 269
 270This supersedes the <<post-update,'post-update'>> hook in that it gets
 271both old and new values of all the refs in addition to their
 272names.
 273
 274Both standard output and standard error output are forwarded to
 275'git send-pack' on the other end, so you can simply `echo` messages
 276for the user.
 277
 278The default 'post-receive' hook is empty, but there is
 279a sample script `post-receive-email` provided in the `contrib/hooks`
 280directory in git distribution, which implements sending commit
 281emails.
 282
 283[[post-update]]
 284post-update
 285~~~~~~~~~~~
 286
 287This hook is invoked by 'git-receive-pack' on the remote repository,
 288which happens when a 'git push' is done on a local repository.
 289It executes on the remote repository once after all the refs have
 290been updated.
 291
 292It takes a variable number of parameters, each of which is the
 293name of ref that was actually updated.
 294
 295This hook is meant primarily for notification, and cannot affect
 296the outcome of 'git-receive-pack'.
 297
 298The 'post-update' hook can tell what are the heads that were pushed,
 299but it does not know what their original and updated values are,
 300so it is a poor place to do log old..new. The
 301<<post-receive,'post-receive'>> hook does get both original and
 302updated values of the refs. You might consider it instead if you need
 303them.
 304
 305When enabled, the default 'post-update' hook runs
 306'git update-server-info' to keep the information used by dumb
 307transports (e.g., HTTP) up-to-date.  If you are publishing
 308a git repository that is accessible via HTTP, you should
 309probably enable this hook.
 310
 311Both standard output and standard error output are forwarded to
 312'git send-pack' on the other end, so you can simply `echo` messages
 313for the user.
 314
 315pre-auto-gc
 316~~~~~~~~~~~
 317
 318This hook is invoked by 'git gc --auto'. It takes no parameter, and
 319exiting with non-zero status from this script causes the 'git gc --auto'
 320to abort.
 321
 322post-rewrite
 323~~~~~~~~~~~~
 324
 325This hook is invoked by commands that rewrite commits (`git commit
 326--amend`, 'git-rebase'; currently 'git-filter-branch' does 'not' call
 327it!).  Its first argument denotes the command it was invoked by:
 328currently one of `amend` or `rebase`.  Further command-dependent
 329arguments may be passed in the future.
 330
 331The hook receives a list of the rewritten commits on stdin, in the
 332format
 333
 334  <old-sha1> SP <new-sha1> [ SP <extra-info> ] LF
 335
 336The 'extra-info' is again command-dependent.  If it is empty, the
 337preceding SP is also omitted.  Currently, no commands pass any
 338'extra-info'.
 339
 340The hook always runs after the automatic note copying (see
 341"notes.rewrite.<command>" in linkgit:git-config.txt[1]) has happened, and
 342thus has access to these notes.
 343
 344The following command-specific comments apply:
 345
 346rebase::
 347        For the 'squash' and 'fixup' operation, all commits that were
 348        squashed are listed as being rewritten to the squashed commit.
 349        This means that there will be several lines sharing the same
 350        'new-sha1'.
 351+
 352The commits are guaranteed to be listed in the order that they were
 353processed by rebase.
 354
 355
 356GIT
 357---
 358Part of the linkgit:git[1] suite