blob: 3e737c236074849377e3766c55f4533a270c436f [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231git-update-ref(1)
2=================
3
4NAME
5----
Junio C Hamano7c73c662007-01-19 00:37:506git-update-ref - Update the object name stored in a ref safely
Junio C Hamano1a4e8412005-12-27 08:17:237
8SYNOPSIS
9--------
Junio C Hamano15567bc2011-07-23 00:51:5910[verse]
Junio C Hamanocae81022018-09-24 18:37:5311'git update-ref' [-m <reason>] [--no-deref] (-d <ref> [<oldvalue>] | [--create-reflog] <ref> <newvalue> [<oldvalue>] | --stdin [-z])
Junio C Hamano1a4e8412005-12-27 08:17:2312
13DESCRIPTION
14-----------
15Given two arguments, stores the <newvalue> in the <ref>, possibly
Junio C Hamanofce7c7e2008-07-02 03:06:3816dereferencing the symbolic refs. E.g. `git update-ref HEAD
Junio C Hamano1a4e8412005-12-27 08:17:2317<newvalue>` updates the current branch head to the new object.
18
19Given three arguments, stores the <newvalue> in the <ref>,
20possibly dereferencing the symbolic refs, after verifying that
21the current value of the <ref> matches <oldvalue>.
Junio C Hamanofce7c7e2008-07-02 03:06:3822E.g. `git update-ref refs/heads/master <newvalue> <oldvalue>`
Junio C Hamano1a4e8412005-12-27 08:17:2323updates the master branch head to <newvalue> only if its current
Junio C Hamanoa2ec14f2006-11-02 00:22:4824value is <oldvalue>. You can specify 40 "0" or an empty string
25as <oldvalue> to make sure that the ref you are creating does
26not exist.
Junio C Hamano1a4e8412005-12-27 08:17:2327
28It also allows a "ref" file to be a symbolic pointer to another
29ref file by starting with the four-byte header sequence of
30"ref:".
31
32More importantly, it allows the update of a ref file to follow
33these symbolic pointers, whether they are symlinks or these
34"regular file symbolic refs". It follows *real* symlinks only
35if they start with "refs/": otherwise it will just try to read
36them and update them as a regular file (i.e. it will allow the
37filesystem to follow them, but will overwrite such a symlink to
38somewhere else with a regular filename).
39
Junio C Hamanof2ce2972007-05-20 19:12:0940If --no-deref is given, <ref> itself is overwritten, rather than
41the result of following the symbolic pointers.
42
Junio C Hamano1a4e8412005-12-27 08:17:2343In general, using
44
Junio C Hamanofce7c7e2008-07-02 03:06:3845git update-ref HEAD "$head"
Junio C Hamano1a4e8412005-12-27 08:17:2346
47should be a _lot_ safer than doing
48
49echo "$head" > "$GIT_DIR/HEAD"
50
51both from a symlink following standpoint *and* an error checking
52standpoint. The "refs/" rule for symlinks means that symlinks
53that point to "outside" the tree are safe: they'll be followed
54for reading but not for writing (so we'll never write through a
55ref symlink to some other tree, if you have copied a whole
56archive by creating a symlink tree).
57
Junio C Hamanoa2ec14f2006-11-02 00:22:4858With `-d` flag, it deletes the named <ref> after verifying it
59still contains <oldvalue>.
60
Junio C Hamano79f4c7c2013-09-20 21:03:3761With `--stdin`, update-ref reads instructions from standard input and
62performs all modifications together. Specify commands of the form:
63
64update SP <ref> SP <newvalue> [SP <oldvalue>] LF
65create SP <ref> SP <newvalue> LF
66delete SP <ref> [SP <oldvalue>] LF
67verify SP <ref> [SP <oldvalue>] LF
68option SP <opt> LF
Junio C Hamano67cc2b72020-04-30 00:03:2069start LF
70prepare LF
71commit LF
72abort LF
Junio C Hamano79f4c7c2013-09-20 21:03:3773
Junio C Hamanod7ed4042015-08-03 19:43:0074With `--create-reflog`, update-ref will create a reflog for each ref
75even if one would not ordinarily be created.
76
Junio C Hamano79f4c7c2013-09-20 21:03:3777Quote fields containing whitespace as if they were strings in C source
Junio C Hamanob051caf2014-06-03 22:15:1378code; i.e., surrounded by double-quotes and with backslash escapes.
79Use 40 "0" characters or the empty string to specify a zero value. To
80specify a missing value, omit the value and its preceding SP entirely.
81
82Alternatively, use `-z` to specify in NUL-terminated format, without
83quoting:
Junio C Hamano79f4c7c2013-09-20 21:03:3784
85update SP <ref> NUL <newvalue> NUL [<oldvalue>] NUL
86create SP <ref> NUL <newvalue> NUL
87delete SP <ref> NUL [<oldvalue>] NUL
88verify SP <ref> NUL [<oldvalue>] NUL
89option SP <opt> NUL
Junio C Hamano67cc2b72020-04-30 00:03:2090start NUL
91prepare NUL
92commit NUL
93abort NUL
Junio C Hamano79f4c7c2013-09-20 21:03:3794
Junio C Hamanob051caf2014-06-03 22:15:1395In this format, use 40 "0" to specify a zero value, and use the empty
96string to specify a missing value.
97
98In either format, values can be specified in any form that Git
99recognizes as an object name. Commands in any other format or a
100repeated <ref> produce an error. Command meanings are:
Junio C Hamano79f4c7c2013-09-20 21:03:37101
102update::
103Set <ref> to <newvalue> after verifying <oldvalue>, if given.
104Specify a zero <newvalue> to ensure the ref does not exist
105after the update and/or a zero <oldvalue> to make sure the
106ref does not exist before the update.
107
108create::
109Create <ref> with <newvalue> after verifying it does not
110exist. The given <newvalue> may not be zero.
111
112delete::
113Delete <ref> after verifying it exists with <oldvalue>, if
114given. If given, <oldvalue> may not be zero.
115
116verify::
117Verify <ref> against <oldvalue> but do not change it. If
Junio C Hamano67cc2b72020-04-30 00:03:20118<oldvalue> is zero or missing, the ref must not exist.
Junio C Hamano79f4c7c2013-09-20 21:03:37119
120option::
121Modify behavior of the next command naming a <ref>.
122The only valid option is `no-deref` to avoid dereferencing
123a symbolic ref.
124
Junio C Hamano67cc2b72020-04-30 00:03:20125start::
126Start a transaction. In contrast to a non-transactional session, a
127transaction will automatically abort if the session ends without an
128explicit commit.
129
130prepare::
131Prepare to commit the transaction. This will create lock files for all
132queued reference updates. If one reference could not be locked, the
133transaction will be aborted.
134
135commit::
136Commit all reference updates queued for the transaction, ending the
137transaction.
138
139abort::
140Abort the transaction, releasing all locks if the transaction is in
141prepared state.
142
Junio C Hamano79f4c7c2013-09-20 21:03:37143If all <ref>s can be locked with matching <oldvalue>s
144simultaneously, all modifications are performed. Otherwise, no
145modifications are performed. Note that while each individual
146<ref> is updated or deleted atomically, a concurrent reader may
147still see a subset of the modifications.
Junio C Hamanoa2ec14f2006-11-02 00:22:48148
Junio C Hamanob9d9d902018-05-23 07:07:42149LOGGING UPDATES
Junio C Hamano341071d2006-06-04 07:24:48150---------------
Junio C Hamano15567bc2011-07-23 00:51:59151If config parameter "core.logAllRefUpdates" is true and the ref is one under
152"refs/heads/", "refs/remotes/", "refs/notes/", or the symbolic ref HEAD; or
153the file "$GIT_DIR/logs/<ref>" exists then `git update-ref` will append
Junio C Hamano341071d2006-06-04 07:24:48154a line to the log file "$GIT_DIR/logs/<ref>" (dereferencing all
155symbolic refs before creating the log name) describing the change
156in ref value. Log lines are formatted as:
157
Junio C Hamano94d00a52018-10-30 07:34:40158 oldsha1 SP newsha1 SP committer LF
159
Junio C Hamano341071d2006-06-04 07:24:48160Where "oldsha1" is the 40 character hexadecimal value previously
161stored in <ref>, "newsha1" is the 40 character hexadecimal value of
162<newvalue> and "committer" is the committer's name, email address
Junio C Hamano076ffcc2013-02-06 05:13:21163and date in the standard Git committer ident format.
Junio C Hamano341071d2006-06-04 07:24:48164
165Optionally with -m:
166
Junio C Hamano94d00a52018-10-30 07:34:40167 oldsha1 SP newsha1 SP committer TAB message LF
168
Junio C Hamano341071d2006-06-04 07:24:48169Where all fields are as described above and "message" is the
170value supplied to the -m option.
171
172An update will fail (without changing <ref>) if the current user is
173unable to create a new log file, append to the existing log file
174or does not have committer information available.
175
Junio C Hamano1a4e8412005-12-27 08:17:23176GIT
177---
Junio C Hamanof7c042d2008-06-06 22:50:53178Part of the linkgit:git[1] suite