blob: bd602c11cf451d6846930d9f7d490f7e582c2952 [file] [log] [blame]
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -07001commit-msg Hook
2===============
3
4NAME
5----
6commit-msg - Edit commit messages to insert a `Change-Id` tag.
7
8DESCRIPTION
9-----------
10
11A Git hook automatically invoked by `git commit`, and most other
12commit creation tools such as `git citool` or `git gui`. The Gerrit
Shawn O. Pearce67a09e82009-08-22 13:30:30 -070013Code Review supplied implementation of this hook is a short shell
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070014script which automatically inserts a globally unique Change-Id tag
15in the footer of a commit message. When present, Gerrit uses this
16tag to track commits across cherry-picks and rebases.
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070017
Shawn O. Pearce67a09e82009-08-22 13:30:30 -070018After the hook has been installed in the user's local Git repository
19for a project, the hook will modify a commit message such as:
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070020
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070021----
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070022 Improve foo widget by attaching a bar.
23
24 We want a bar, because it improves the foo by providing more
25 wizbangery to the dowhatimeanery.
26
27 Signed-off-by: A. U. Thor <author@example.com>
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070028----
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070029
Shawn O. Pearce67a09e82009-08-22 13:30:30 -070030by inserting a new `Change-Id: ` line in the footer:
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070031
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070032----
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070033 Improve foo widget by attaching a bar.
34
35 We want a bar, because it improves the foo by providing more
36 wizbangery to the dowhatimeanery.
37
38 Change-Id: Ic8aaa0728a43936cd4c6e1ed590e01ba8f0fbf5b
39 Signed-off-by: A. U. Thor <author@example.com>
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070040----
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070041
Shawn O. Pearce67a09e82009-08-22 13:30:30 -070042The hook implementation is reasonably intelligent at inserting the
43Change-Id line before any Signed-off-by or Acked-by lines placed
44at the end of the commit message by the author, but if no such
45lines are present then it will just insert a blank line, and add
46the Change-Id at the bottom of the message.
47
48If a Change-Id line is already present in the message footer, the
49script will do nothing, leaving the existing Change-Id unmodified.
50This permits amending an existing commit, or allows the user to
51insert the Change-Id manually after copying it from an existing
52change viewed on the web.
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070053
54OBTAINING
55---------
Fredrik Luthanderfb9536d2011-10-28 07:00:53 +020056To obtain the 'commit-msg' script use scp, wget or curl to download it
David Pursehouse221d4f62012-06-08 17:38:08 +090057to your local system from your Gerrit server.
Fredrik Luthanderfb9536d2011-10-28 07:00:53 +020058
59You can use either of the below commands:
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070060
Shawn O. Pearce47769242011-06-14 16:40:48 -070061====
Fredrik Luthanderfb9536d2011-10-28 07:00:53 +020062 $ scp -p -P 29418 <your username>@<your Gerrit review server>:hooks/commit-msg <local path to your git>/.git/hooks/
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070063
Fredrik Luthanderfb9536d2011-10-28 07:00:53 +020064 $ curl -o <local path to your git>/.git/hooks/commit-msg <your Gerrit http URL>/tools/hooks/commit-msg
65====
66
67A specific example of this might look something like this:
68
69.Example
70====
71 $ scp -p -P 29418 john.doe@review.example.com:hooks/commit-msg ~/duhproject/.git/hooks/
72
73 $ curl -o ~/duhproject/.git/hooks/commit-msg http://review.example.com/tools/hooks/commit-msg
Shawn O. Pearce47769242011-06-14 16:40:48 -070074====
Shawn O. Pearce3e4e8042010-01-29 12:48:21 -080075
David Pursehouse056ed182012-08-16 10:19:14 +090076Make sure the hook file is executable:
77
78====
79 $ chmod u+x ~/duhproject/.git/hooks/commit-msg
80====
81
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070082SEE ALSO
83--------
84
85* link:user-changeid.html[Change-Id Lines]
86* link:http://www.kernel.org/pub/software/scm/git/docs/git-commit.html[git-commit(1)]
87* link:http://www.kernel.org/pub/software/scm/git/docs/githooks.html[githooks(5)]
88
89IMPLEMENTATION
90--------------
91
92The hook generates unique Change-Id lines by creating a virtual
93commit object within the local Git repository, and obtaining the
94SHA-1 hash from it. Like any other Git commit, the following
95properties are included in the computation:
96
97* SHA-1 of the tree being committed
98* SHA-1 of the parent commit
99* Name, email address, timestamp of the author
100* Name, email address, timestamp of the committer
101* Proposed commit message (before Change-Id was inserted)
102
103Because the names of the tree and parent commit, as well as the
104committer timestamp are included in the hash computation, the output
105Change-Id is sufficiently unique.
106
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -0700107GERRIT
108------
109Part of link:index.html[Gerrit Code Review]