Skip to content

Commit 2db6067

Browse files
mhaggergitster
authored andcommitted
rev-parse: clarify documentation for the --verify option
The old version could be read to mean that the argument has to refer to a valid object, but that is incorrect: * the object is not necessarily read (e.g., to check for corruption) * if the argument is a 40-digit string of hex digits, then it is accepted whether or not is is the name of an existing object. So reword the explanation to be less ambiguous. Also fix the examples involving --verify: to be sure that the argument refers to a commit (rather than some other kind of object), the argument has to be suffixed with "^{commit}". This trick is not possible in the example involving --default, so don't imply that it is exactly the same as the previous example. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a6a3f2c commit 2db6067

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Documentation/git-rev-parse.txt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,19 @@ OPTIONS
6060
instead.
6161

6262
--verify::
63-
The parameter given must be usable as a single, valid
64-
object name. Otherwise barf and abort.
63+
Verify that exactly one parameter is provided, and that it
64+
can be turned into a raw 20-byte SHA-1 that can be used to
65+
access the object database. If so, emit it to the standard
66+
output; otherwise, error out.
67+
+
68+
If you want to make sure that the output actually names an object in
69+
your object database and/or can be used as a specific type of object
70+
you require, you can add "^{type}" peeling operator to the parmeter.
71+
For example, `git rev-parse "$VAR^{commit}"` will make sure `$VAR`
72+
names an existing object that is a commit-ish (i.e. a commit, or an
73+
annotated tag that points at a commit). To make sure that `$VAR`
74+
names an existing object of any type, `git rev-parse "$VAR^{object}"`
75+
can be used.
6576

6677
-q::
6778
--quiet::
@@ -306,12 +317,12 @@ $ git rev-parse --verify HEAD
306317
* Print the commit object name from the revision in the $REV shell variable:
307318
+
308319
------------
309-
$ git rev-parse --verify $REV
320+
$ git rev-parse --verify $REV^{commit}
310321
------------
311322
+
312323
This will error out if $REV is empty or not a valid revision.
313324

314-
* Same as above:
325+
* Similar to above:
315326
+
316327
------------
317328
$ git rev-parse --default master --verify $REV

0 commit comments

Comments
 (0)