]>
Commit | Line | Data |
---|---|---|
622ef9df JH |
1 | git-check-ref-format(1) |
2 | ======================= | |
3 | ||
4 | NAME | |
5 | ---- | |
cd747dc6 | 6 | git-check-ref-format - Ensures that a reference name is well formed |
622ef9df JH |
7 | |
8 | SYNOPSIS | |
9 | -------- | |
a31dca03 | 10 | [verse] |
b1889c36 | 11 | 'git check-ref-format' <refname> |
38eedc63 | 12 | 'git check-ref-format' --print <refname> |
604e0cb5 | 13 | 'git check-ref-format' --branch <branchname-shorthand> |
622ef9df JH |
14 | |
15 | DESCRIPTION | |
16 | ----------- | |
cd747dc6 DM |
17 | Checks if a given 'refname' is acceptable, and exits with a non-zero |
18 | status if it is not. | |
622ef9df JH |
19 | |
20 | A reference is used in git to specify branches and tags. A | |
cd747dc6 DM |
21 | branch head is stored under the `$GIT_DIR/refs/heads` directory, and |
22 | a tag is stored under the `$GIT_DIR/refs/tags` directory. git | |
23 | imposes the following rules on how references are named: | |
622ef9df | 24 | |
cd747dc6 | 25 | . They can include slash `/` for hierarchical (directory) |
37425065 | 26 | grouping, but no slash-separated component can begin with a |
cd747dc6 | 27 | dot `.`. |
622ef9df | 28 | |
1a287259 MG |
29 | . They must contain at least one `/`. This enforces the presence of a |
30 | category like `heads/`, `tags/` etc. but the actual names are not | |
31 | restricted. | |
32 | ||
cd747dc6 | 33 | . They cannot have two consecutive dots `..` anywhere. |
622ef9df | 34 | |
cd747dc6 | 35 | . They cannot have ASCII control characters (i.e. bytes whose |
622ef9df | 36 | values are lower than \040, or \177 `DEL`), space, tilde `~`, |
68283999 | 37 | caret `{caret}`, colon `:`, question-mark `?`, asterisk `*`, |
cd747dc6 | 38 | or open bracket `[` anywhere. |
622ef9df | 39 | |
cbdffe40 JH |
40 | . They cannot end with a slash `/` nor a dot `.`. |
41 | ||
3e262b95 SP |
42 | . They cannot end with the sequence `.lock`. |
43 | ||
cbdffe40 | 44 | . They cannot contain a sequence `@{`. |
622ef9df | 45 | |
a4c2e699 RR |
46 | - They cannot contain a `\\`. |
47 | ||
cd747dc6 DM |
48 | These rules make it easy for shell script based tools to parse |
49 | reference names, pathname expansion by the shell when a reference name is used | |
68283999 | 50 | unquoted (by mistake), and also avoids ambiguities in certain |
cd747dc6 | 51 | reference name expressions (see linkgit:git-rev-parse[1]): |
622ef9df | 52 | |
cd747dc6 DM |
53 | . A double-dot `..` is often used as in `ref1..ref2`, and in some |
54 | contexts this notation means `{caret}ref1 ref2` (i.e. not in | |
55 | `ref1` and in `ref2`). | |
622ef9df | 56 | |
cd747dc6 | 57 | . A tilde `~` and caret `{caret}` are used to introduce the postfix |
622ef9df JH |
58 | 'nth parent' and 'peel onion' operation. |
59 | ||
cd747dc6 | 60 | . A colon `:` is used as in `srcref:dstref` to mean "use srcref\'s |
622ef9df | 61 | value and store it in dstref" in fetch and push operations. |
87a56cd3 | 62 | It may also be used to select a specific object such as with |
ba020ef5 | 63 | 'git-cat-file': "git cat-file blob v1.3.3:refs.c". |
622ef9df | 64 | |
cbdffe40 JH |
65 | . at-open-brace `@{` is used as a notation to access a reflog entry. |
66 | ||
38eedc63 JH |
67 | With the `--print` option, if 'refname' is acceptable, it prints the |
68 | canonicalized name of a hypothetical reference with that name. That is, | |
69 | it prints 'refname' with any extra `/` characters removed. | |
70 | ||
604e0cb5 JN |
71 | With the `--branch` option, it expands the ``previous branch syntax'' |
72 | `@{-n}`. For example, `@{-1}` is a way to refer the last branch you | |
73 | were on. This option should be used by porcelains to accept this | |
74 | syntax anywhere a branch name is expected, so they can act as if you | |
75 | typed the branch name. | |
a31dca03 | 76 | |
38eedc63 JH |
77 | EXAMPLES |
78 | -------- | |
a31dca03 | 79 | |
38eedc63 JH |
80 | * Print the name of the previous branch: |
81 | + | |
82 | ------------ | |
83 | $ git check-ref-format --branch @{-1} | |
84 | ------------ | |
85 | ||
86 | * Determine the reference name to use for a new branch: | |
87 | + | |
88 | ------------ | |
89 | $ ref=$(git check-ref-format --print "refs/heads/$newbranch") || | |
90 | die "we do not like '$newbranch' as a branch name." | |
91 | ------------ | |
622ef9df JH |
92 | |
93 | GIT | |
94 | --- | |
9e1f0a85 | 95 | Part of the linkgit:git[1] suite |