Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 1 | git-show-ref(1) |
| 2 | =============== |
| 3 | |
| 4 | NAME |
| 5 | ---- |
| 6 | git-show-ref - List references in a local repository |
| 7 | |
| 8 | SYNOPSIS |
| 9 | -------- |
| 10 | [verse] |
Ævar Arnfjörð Bjarmason | e2f4e7e | 2022-10-13 17:39:06 +0200 | [diff] [blame] | 11 | 'git show-ref' [-q | --quiet] [--verify] [--head] [-d | --dereference] |
| 12 | [-s | --hash[=<n>]] [--abbrev[=<n>]] [--tags] |
Holger Weiß | 4318d3b | 2010-03-29 13:02:37 +0200 | [diff] [blame] | 13 | [--heads] [--] [<pattern>...] |
Junio C Hamano | 33e8fc8 | 2015-10-16 11:27:42 -0700 | [diff] [blame] | 14 | 'git show-ref' --exclude-existing[=<pattern>] |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 15 | |
| 16 | DESCRIPTION |
| 17 | ----------- |
| 18 | |
| 19 | Displays references available in a local repository along with the associated |
| 20 | commit IDs. Results can be filtered using a pattern and tags can be |
| 21 | dereferenced into object IDs. Additionally, it can be used to test whether a |
| 22 | particular ref exists. |
| 23 | |
Doug Bell | 3f3d0ce | 2013-07-16 19:05:14 -0500 | [diff] [blame] | 24 | By default, shows the tags, heads, and remote refs. |
| 25 | |
Sean Allred | 00bf685 | 2023-05-19 04:17:49 +0000 | [diff] [blame] | 26 | The `--exclude-existing` form is a filter that does the inverse. It reads |
Junio C Hamano | 33e8fc8 | 2015-10-16 11:27:42 -0700 | [diff] [blame] | 27 | refs from stdin, one ref per line, and shows those that don't exist in |
| 28 | the local repository. |
Julian Phillips | 8bd26c4 | 2007-04-09 21:57:36 +0100 | [diff] [blame] | 29 | |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 30 | Use of this utility is encouraged in favor of directly accessing files under |
Stephen Boyd | d4900ee | 2009-06-20 21:40:45 -0700 | [diff] [blame] | 31 | the `.git` directory. |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 32 | |
| 33 | OPTIONS |
| 34 | ------- |
| 35 | |
Stephan Beyer | 3240240 | 2008-06-08 03:36:09 +0200 | [diff] [blame] | 36 | --head:: |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 37 | |
Doug Bell | 3f3d0ce | 2013-07-16 19:05:14 -0500 | [diff] [blame] | 38 | Show the HEAD reference, even if it would normally be filtered out. |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 39 | |
Stephan Beyer | 3240240 | 2008-06-08 03:36:09 +0200 | [diff] [blame] | 40 | --heads:: |
Elijah Newren | bd8d6f0 | 2019-01-09 11:58:47 -0800 | [diff] [blame] | 41 | --tags:: |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 42 | |
Doug Bell | 3f3d0ce | 2013-07-16 19:05:14 -0500 | [diff] [blame] | 43 | Limit to "refs/heads" and "refs/tags", respectively. These options |
| 44 | are not mutually exclusive; when given both, references stored in |
| 45 | "refs/heads" and "refs/tags" are displayed. |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 46 | |
Stephan Beyer | 3240240 | 2008-06-08 03:36:09 +0200 | [diff] [blame] | 47 | -d:: |
| 48 | --dereference:: |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 49 | |
Martin Ågren | 18c4aac | 2023-08-16 16:24:35 +0200 | [diff] [blame] | 50 | Dereference tags into object IDs as well. They will be shown with `^{}` |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 51 | appended. |
| 52 | |
Stephan Beyer | 3240240 | 2008-06-08 03:36:09 +0200 | [diff] [blame] | 53 | -s:: |
Stephen Boyd | 69932bc | 2009-06-20 21:40:46 -0700 | [diff] [blame] | 54 | --hash[=<n>]:: |
Christian Couder | 9581e0f | 2006-09-20 06:14:54 +0200 | [diff] [blame] | 55 | |
Sean Allred | 00bf685 | 2023-05-19 04:17:49 +0000 | [diff] [blame] | 56 | Only show the OID, not the reference name. When combined with |
| 57 | `--dereference`, the dereferenced tag will still be shown after the OID. |
Christian Couder | 9581e0f | 2006-09-20 06:14:54 +0200 | [diff] [blame] | 58 | |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 59 | --verify:: |
| 60 | |
| 61 | Enable stricter reference checking by requiring an exact ref path. |
| 62 | Aside from returning an error code of 1, it will also print an error |
Matthieu Moy | bcf9626 | 2016-06-28 13:40:11 +0200 | [diff] [blame] | 63 | message if `--quiet` was not specified. |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 64 | |
Stephen Boyd | 69932bc | 2009-06-20 21:40:46 -0700 | [diff] [blame] | 65 | --abbrev[=<n>]:: |
Junio C Hamano | 2eaf222 | 2006-10-01 00:27:27 -0700 | [diff] [blame] | 66 | |
| 67 | Abbreviate the object name. When using `--hash`, you do |
Stephen Boyd | 69932bc | 2009-06-20 21:40:46 -0700 | [diff] [blame] | 68 | not have to say `--hash --abbrev`; `--hash=n` would do. |
Junio C Hamano | 2eaf222 | 2006-10-01 00:27:27 -0700 | [diff] [blame] | 69 | |
Stephan Beyer | 3240240 | 2008-06-08 03:36:09 +0200 | [diff] [blame] | 70 | -q:: |
| 71 | --quiet:: |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 72 | |
Sean Allred | 00bf685 | 2023-05-19 04:17:49 +0000 | [diff] [blame] | 73 | Do not print any results to stdout. When combined with `--verify`, this |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 74 | can be used to silently check if a reference exists. |
| 75 | |
Stephen Boyd | 69932bc | 2009-06-20 21:40:46 -0700 | [diff] [blame] | 76 | --exclude-existing[=<pattern>]:: |
Julian Phillips | 8bd26c4 | 2007-04-09 21:57:36 +0100 | [diff] [blame] | 77 | |
Sean Allred | 00bf685 | 2023-05-19 04:17:49 +0000 | [diff] [blame] | 78 | Make `git show-ref` act as a filter that reads refs from stdin of the |
| 79 | form `^(?:<anything>\s)?<refname>(?:\^{})?$` |
Jonathan Nieder | f100598 | 2010-08-20 05:23:54 -0500 | [diff] [blame] | 80 | and performs the following actions on each: |
Martin Ågren | 18c4aac | 2023-08-16 16:24:35 +0200 | [diff] [blame] | 81 | (1) strip `^{}` at the end of line if any; |
Julian Phillips | 8bd26c4 | 2007-04-09 21:57:36 +0100 | [diff] [blame] | 82 | (2) ignore if pattern is provided and does not head-match refname; |
| 83 | (3) warn if refname is not a well-formed refname and skip; |
| 84 | (4) ignore if refname is a ref that exists in the local repository; |
| 85 | (5) otherwise output the line. |
| 86 | |
| 87 | |
Abhijit Menon-Sen | f448e24 | 2008-07-30 15:03:43 +0530 | [diff] [blame] | 88 | <pattern>...:: |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 89 | |
Michael J Gruber | 9fbd898 | 2010-10-18 13:33:32 +0200 | [diff] [blame] | 90 | Show references matching one or more patterns. Patterns are matched from |
| 91 | the end of the full name, and only complete parts are matched, e.g. |
| 92 | 'master' matches 'refs/heads/master', 'refs/remotes/origin/master', |
Justin Lebar | a58088a | 2014-03-31 15:11:44 -0700 | [diff] [blame] | 93 | 'refs/tags/jedi/master' but not 'refs/heads/mymaster' or |
Michael J Gruber | 9fbd898 | 2010-10-18 13:33:32 +0200 | [diff] [blame] | 94 | 'refs/remotes/master/jedi'. |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 95 | |
| 96 | OUTPUT |
| 97 | ------ |
| 98 | |
Sean Allred | 00bf685 | 2023-05-19 04:17:49 +0000 | [diff] [blame] | 99 | The output is in the format: |
| 100 | |
| 101 | ------------ |
| 102 | <oid> SP <ref> LF |
| 103 | ------------ |
| 104 | |
| 105 | For example, |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 106 | |
| 107 | ----------------------------------------------------------------------------- |
| 108 | $ git show-ref --head --dereference |
| 109 | 832e76a9899f560a90ffd62ae2ce83bbeff58f54 HEAD |
| 110 | 832e76a9899f560a90ffd62ae2ce83bbeff58f54 refs/heads/master |
| 111 | 832e76a9899f560a90ffd62ae2ce83bbeff58f54 refs/heads/origin |
| 112 | 3521017556c5de4159da4615a39fa4d5d2c279b5 refs/tags/v0.99.9c |
| 113 | 6ddc0964034342519a87fe013781abf31c6db6ad refs/tags/v0.99.9c^{} |
| 114 | 055e4ae3ae6eb344cbabf2a5256a49ea66040131 refs/tags/v1.0rc4 |
| 115 | 423325a2d24638ddcc82ce47be5e40be550f4507 refs/tags/v1.0rc4^{} |
| 116 | ... |
| 117 | ----------------------------------------------------------------------------- |
| 118 | |
Sean Allred | 00bf685 | 2023-05-19 04:17:49 +0000 | [diff] [blame] | 119 | When using `--hash` (and not `--dereference`), the output is in the format: |
| 120 | |
| 121 | ------------ |
| 122 | <oid> LF |
| 123 | ------------ |
| 124 | |
| 125 | For example, |
Christian Couder | 9581e0f | 2006-09-20 06:14:54 +0200 | [diff] [blame] | 126 | |
| 127 | ----------------------------------------------------------------------------- |
| 128 | $ git show-ref --heads --hash |
| 129 | 2e3ba0114a1f52b47df29743d6915d056be13278 |
| 130 | 185008ae97960c8d551adcd9e23565194651b5d1 |
| 131 | 03adf42c988195b50e1a1935ba5fcbc39b2b029b |
| 132 | ... |
| 133 | ----------------------------------------------------------------------------- |
| 134 | |
Nguyễn Thái Ngọc Duy | 76a8788 | 2018-04-30 17:35:33 +0200 | [diff] [blame] | 135 | EXAMPLES |
| 136 | -------- |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 137 | |
| 138 | To show all references called "master", whether tags or heads or anything |
| 139 | else, and regardless of how deep in the reference naming hierarchy they are, |
| 140 | use: |
| 141 | |
| 142 | ----------------------------------------------------------------------------- |
| 143 | git show-ref master |
| 144 | ----------------------------------------------------------------------------- |
| 145 | |
| 146 | This will show "refs/heads/master" but also "refs/remote/other-repo/master", |
Elijah Newren | ce14cc0 | 2023-10-08 06:45:09 +0000 | [diff] [blame] | 147 | if such references exist. |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 148 | |
Matthieu Moy | bcf9626 | 2016-06-28 13:40:11 +0200 | [diff] [blame] | 149 | When using the `--verify` flag, the command requires an exact path: |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 150 | |
| 151 | ----------------------------------------------------------------------------- |
| 152 | git show-ref --verify refs/heads/master |
| 153 | ----------------------------------------------------------------------------- |
| 154 | |
| 155 | will only match the exact branch called "master". |
| 156 | |
Sean Allred | 00bf685 | 2023-05-19 04:17:49 +0000 | [diff] [blame] | 157 | If nothing matches, `git show-ref` will return an error code of 1, |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 158 | and in the case of verification, it will show an error message. |
| 159 | |
Sean Allred | 00bf685 | 2023-05-19 04:17:49 +0000 | [diff] [blame] | 160 | For scripting, you can ask it to be quiet with the `--quiet` flag, which |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 161 | allows you to do things like |
| 162 | |
| 163 | ----------------------------------------------------------------------------- |
Jonathan Nieder | b1889c3 | 2008-06-30 01:09:04 -0500 | [diff] [blame] | 164 | git show-ref --quiet --verify -- "refs/heads/$headname" || |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 165 | echo "$headname is not a valid branch" |
| 166 | ----------------------------------------------------------------------------- |
| 167 | |
| 168 | to check whether a particular branch exists or not (notice how we don't |
| 169 | actually want to show any results, and we want to use the full refname for it |
| 170 | in order to not trigger the problem with ambiguous partial matches). |
| 171 | |
Sean Allred | 00bf685 | 2023-05-19 04:17:49 +0000 | [diff] [blame] | 172 | To show only tags, or only proper branch heads, use `--tags` and/or `--heads` |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 173 | respectively (using both means that it shows tags and heads, but not other |
| 174 | random references under the refs/ subdirectory). |
| 175 | |
Sean Allred | 00bf685 | 2023-05-19 04:17:49 +0000 | [diff] [blame] | 176 | To do automatic tag object dereferencing, use the `-d` or `--dereference` |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 177 | flag, so you can do |
| 178 | |
| 179 | ----------------------------------------------------------------------------- |
| 180 | git show-ref --tags --dereference |
| 181 | ----------------------------------------------------------------------------- |
| 182 | |
| 183 | to get a listing of all tags together with what they dereference. |
| 184 | |
Jonathan Nieder | 977ed83 | 2010-08-08 20:32:43 -0500 | [diff] [blame] | 185 | FILES |
| 186 | ----- |
| 187 | `.git/refs/*`, `.git/packed-refs` |
| 188 | |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 189 | SEE ALSO |
| 190 | -------- |
Michael Haggerty | f21e1c5 | 2014-01-22 12:23:20 +0100 | [diff] [blame] | 191 | linkgit:git-for-each-ref[1], |
Jonathan Nieder | 977ed83 | 2010-08-08 20:32:43 -0500 | [diff] [blame] | 192 | linkgit:git-ls-remote[1], |
| 193 | linkgit:git-update-ref[1], |
| 194 | linkgit:gitrepository-layout[5] |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 195 | |
Jonas Fonseca | c0990ff | 2006-09-18 14:32:41 +0200 | [diff] [blame] | 196 | GIT |
| 197 | --- |
Christian Couder | 9e1f0a8 | 2008-06-06 09:07:32 +0200 | [diff] [blame] | 198 | Part of the linkgit:git[1] suite |