blob: 49d5c173be514881f4a98f51584acab08b48291c [file] [log] [blame]
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -08001= commit-msg Hook
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -07002
David Pursehousebecc8d42013-08-08 15:06:24 +09003
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -08004== NAME
David Pursehousebecc8d42013-08-08 15:06:24 +09005
6
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -07007commit-msg - Edit commit messages to insert a `Change-Id` tag.
8
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -08009== DESCRIPTION
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070010
David Pursehousebecc8d42013-08-08 15:06:24 +090011
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070012A Git hook automatically invoked by `git commit`, and most other
13commit creation tools such as `git citool` or `git gui`. The Gerrit
Shawn O. Pearce67a09e82009-08-22 13:30:30 -070014Code Review supplied implementation of this hook is a short shell
David Pursehousebecc8d42013-08-08 15:06:24 +090015script which automatically inserts a globally unique `Change-Id` tag
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070016in the footer of a commit message. When present, Gerrit uses this
17tag to track commits across cherry-picks and rebases.
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070018
Shawn O. Pearce67a09e82009-08-22 13:30:30 -070019After the hook has been installed in the user's local Git repository
20for a project, the hook will modify a commit message such as:
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070021
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070022----
David Shevitzb1a96522018-09-24 10:33:11 -070023Improve foo widget by attaching a bar.
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070024
David Shevitzb1a96522018-09-24 10:33:11 -070025We want a bar, because it improves the foo by providing more
26wizbangery to the dowhatimeanery.
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070027
David Shevitzb1a96522018-09-24 10:33:11 -070028Signed-off-by: A. U. Thor <author@example.com>
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070029----
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070030
Shawn O. Pearce67a09e82009-08-22 13:30:30 -070031by inserting a new `Change-Id: ` line in the footer:
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070032
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070033----
David Shevitzb1a96522018-09-24 10:33:11 -070034Improve foo widget by attaching a bar.
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070035
David Shevitzb1a96522018-09-24 10:33:11 -070036We want a bar, because it improves the foo by providing more
37wizbangery to the dowhatimeanery.
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070038
David Shevitzb1a96522018-09-24 10:33:11 -070039Change-Id: Ic8aaa0728a43936cd4c6e1ed590e01ba8f0fbf5b
40Signed-off-by: A. U. Thor <author@example.com>
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070041----
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070042
Shawn O. Pearce67a09e82009-08-22 13:30:30 -070043The hook implementation is reasonably intelligent at inserting the
David Pursehousebecc8d42013-08-08 15:06:24 +090044`Change-Id` line before any `Signed-off-by` or `Acked-by` lines placed
Shawn O. Pearce67a09e82009-08-22 13:30:30 -070045at the end of the commit message by the author, but if no such
46lines are present then it will just insert a blank line, and add
David Pursehousebecc8d42013-08-08 15:06:24 +090047the `Change-Id` at the bottom of the message.
Shawn O. Pearce67a09e82009-08-22 13:30:30 -070048
David Pursehousebecc8d42013-08-08 15:06:24 +090049If a `Change-Id` line is already present in the message footer, the
50script will do nothing, leaving the existing `Change-Id` unmodified.
Shawn O. Pearce67a09e82009-08-22 13:30:30 -070051This permits amending an existing commit, or allows the user to
52insert the Change-Id manually after copying it from an existing
53change viewed on the web.
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070054
David Pursehousec05da5b52013-08-08 15:09:12 +090055The `Change-Id` will not be added if `gerrit.createChangeId` is set
56to `false` in the git config.
57
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080058== OBTAINING
David Pursehousebecc8d42013-08-08 15:06:24 +090059
David Pursehousebecc8d42013-08-08 15:06:24 +090060To obtain the `commit-msg` script use `scp`, `wget` or `curl` to download
61it to your local system from your Gerrit server.
Fredrik Luthanderfb9536d2011-10-28 07:00:53 +020062
63You can use either of the below commands:
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -070064
Michael Ochmannb99feab2016-07-06 14:10:22 +020065----
David Shevitzb1a96522018-09-24 10:33:11 -070066$ 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 -070067
David Shevitzb1a96522018-09-24 10:33:11 -070068$ curl -Lo <local path to your git>/.git/hooks/commit-msg <your Gerrit http URL>/tools/hooks/commit-msg
Michael Ochmannb99feab2016-07-06 14:10:22 +020069----
Fredrik Luthanderfb9536d2011-10-28 07:00:53 +020070
71A specific example of this might look something like this:
72
Michael Ochmannb99feab2016-07-06 14:10:22 +020073----
David Shevitzb1a96522018-09-24 10:33:11 -070074$ scp -p -P 29418 john.doe@review.example.com:hooks/commit-msg ~/duhproject/.git/hooks/
Fredrik Luthanderfb9536d2011-10-28 07:00:53 +020075
David Shevitzb1a96522018-09-24 10:33:11 -070076$ curl -Lo ~/duhproject/.git/hooks/commit-msg http://review.example.com/tools/hooks/commit-msg
Michael Ochmannb99feab2016-07-06 14:10:22 +020077----
Shawn O. Pearce3e4e8042010-01-29 12:48:21 -080078
David Pursehouse056ed182012-08-16 10:19:14 +090079Make sure the hook file is executable:
80
Michael Ochmannb99feab2016-07-06 14:10:22 +020081----
David Shevitzb1a96522018-09-24 10:33:11 -070082$ chmod u+x ~/duhproject/.git/hooks/commit-msg
Michael Ochmannb99feab2016-07-06 14:10:22 +020083----
David Pursehouse056ed182012-08-16 10:19:14 +090084
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080085== SEE ALSO
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070086
David Pursehousebecc8d42013-08-08 15:06:24 +090087
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070088* link:user-changeid.html[Change-Id Lines]
89* link:http://www.kernel.org/pub/software/scm/git/docs/git-commit.html[git-commit(1)]
90* link:http://www.kernel.org/pub/software/scm/git/docs/githooks.html[githooks(5)]
91
Yuxuan 'fishy' Wang61698b12013-12-20 12:55:51 -080092== IMPLEMENTATION
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070093
David Pursehousebecc8d42013-08-08 15:06:24 +090094
95The hook generates unique `Change-Id` lines by creating a virtual
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -070096commit object within the local Git repository, and obtaining the
97SHA-1 hash from it. Like any other Git commit, the following
98properties are included in the computation:
99
100* SHA-1 of the tree being committed
101* SHA-1 of the parent commit
102* Name, email address, timestamp of the author
103* Name, email address, timestamp of the committer
David Pursehousebecc8d42013-08-08 15:06:24 +0900104* Proposed commit message (before `Change-Id` was inserted)
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -0700105
106Because the names of the tree and parent commit, as well as the
107committer timestamp are included in the hash computation, the output
David Pursehousebecc8d42013-08-08 15:06:24 +0900108`Change-Id` is sufficiently unique.
Shawn O. Pearce518fe3f2009-08-22 15:40:58 -0700109
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -0700110GERRIT
111------
Shawn O. Pearcebb2b5672009-08-21 18:33:10 -0700112Part of link:index.html[Gerrit Code Review]
Yuxuan 'fishy' Wang99cb68d2013-10-31 17:26:00 -0700113
114SEARCHBOX
115---------