]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-update-ref.txt
Start the 2.46 cycle
[thirdparty/git.git] / Documentation / git-update-ref.txt
CommitLineData
12905637
JH
1git-update-ref(1)
2=================
3
4NAME
5----
c3f0baac 6git-update-ref - Update the object name stored in a ref safely
12905637
JH
7
8SYNOPSIS
9--------
7791a1d9 10[verse]
67e943c3 11'git update-ref' [-m <reason>] [--no-deref] (-d <ref> [<old-oid>] | [--create-reflog] <ref> <new-oid> [<old-oid>] | --stdin [-z])
12905637
JH
12
13DESCRIPTION
14-----------
67e943c3 15Given two arguments, stores the <new-oid> in the <ref>, possibly
b1889c36 16dereferencing the symbolic refs. E.g. `git update-ref HEAD
67e943c3 17<new-oid>` updates the current branch head to the new object.
12905637 18
67e943c3 19Given three arguments, stores the <new-oid> in the <ref>,
12905637 20possibly dereferencing the symbolic refs, after verifying that
67e943c3
KN
21the current value of the <ref> matches <old-oid>.
22E.g. `git update-ref refs/heads/master <new-oid> <old-oid>`
23updates the master branch head to <new-oid> only if its current
24value is <old-oid>. You can specify 40 "0" or an empty string
25as <old-oid> to make sure that the ref you are creating does
ac5409e4 26not exist.
12905637
JH
27
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
68db31cc
SV
40If --no-deref is given, <ref> itself is overwritten, rather than
41the result of following the symbolic pointers.
42
12905637
JH
43In general, using
44
b1889c36 45 git update-ref HEAD "$head"
12905637
JH
46
47should be a _lot_ safer than doing
48
49 echo "$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
ac5409e4 58With `-d` flag, it deletes the named <ref> after verifying it
67e943c3 59still contains <old-oid>.
ac5409e4 60
c750ba95
BK
61With `--stdin`, update-ref reads instructions from standard input and
62performs all modifications together. Specify commands of the form:
63
67e943c3
KN
64 update SP <ref> SP <new-oid> [SP <old-oid>] LF
65 create SP <ref> SP <new-oid> LF
66 delete SP <ref> [SP <old-oid>] LF
67 verify SP <ref> [SP <old-oid>] LF
c750ba95 68 option SP <opt> LF
e48cf33b
PS
69 start LF
70 prepare LF
71 commit LF
72 abort LF
c750ba95 73
144c76fa
DT
74With `--create-reflog`, update-ref will create a reflog for each ref
75even if one would not ordinarily be created.
76
c750ba95 77Quote fields containing whitespace as if they were strings in C source
1fbd5049
MH
78code; 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:
c750ba95 84
67e943c3
KN
85 update SP <ref> NUL <new-oid> NUL [<old-oid>] NUL
86 create SP <ref> NUL <new-oid> NUL
87 delete SP <ref> NUL [<old-oid>] NUL
88 verify SP <ref> NUL [<old-oid>] NUL
c750ba95 89 option SP <opt> NUL
e48cf33b
PS
90 start NUL
91 prepare NUL
92 commit NUL
93 abort NUL
c750ba95 94
1fbd5049
MH
95In 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:
c750ba95
BK
101
102update::
67e943c3
KN
103 Set <ref> to <new-oid> after verifying <old-oid>, if given.
104 Specify a zero <new-oid> to ensure the ref does not exist
105 after the update and/or a zero <old-oid> to make sure the
c750ba95
BK
106 ref does not exist before the update.
107
108create::
67e943c3
KN
109 Create <ref> with <new-oid> after verifying it does not
110 exist. The given <new-oid> may not be zero.
c750ba95
BK
111
112delete::
67e943c3
KN
113 Delete <ref> after verifying it exists with <old-oid>, if
114 given. If given, <old-oid> may not be zero.
c750ba95
BK
115
116verify::
67e943c3
KN
117 Verify <ref> against <old-oid> but do not change it. If
118 <old-oid> is zero or missing, the ref must not exist.
c750ba95
BK
119
120option::
0a4f051f 121 Modify the behavior of the next command naming a <ref>.
c750ba95
BK
122 The only valid option is `no-deref` to avoid dereferencing
123 a symbolic ref.
124
e48cf33b
PS
125start::
126 Start a transaction. In contrast to a non-transactional session, a
127 transaction will automatically abort if the session ends without an
262a4d28
PS
128 explicit commit. This command may create a new empty transaction when
129 the current one has been committed or aborted already.
e48cf33b
PS
130
131prepare::
132 Prepare to commit the transaction. This will create lock files for all
133 queued reference updates. If one reference could not be locked, the
134 transaction will be aborted.
135
136commit::
137 Commit all reference updates queued for the transaction, ending the
138 transaction.
139
140abort::
141 Abort the transaction, releasing all locks if the transaction is in
142 prepared state.
143
67e943c3 144If all <ref>s can be locked with matching <old-oid>s
c750ba95
BK
145simultaneously, all modifications are performed. Otherwise, no
146modifications are performed. Note that while each individual
147<ref> is updated or deleted atomically, a concurrent reader may
148still see a subset of the modifications.
ac5409e4 149
76a8788c 150LOGGING UPDATES
6de08ae6 151---------------
09743417
HWN
152If config parameter "core.logAllRefUpdates" is true and the ref is one
153under "refs/heads/", "refs/remotes/", "refs/notes/", or a pseudoref
154like HEAD or ORIG_HEAD; or the file "$GIT_DIR/logs/<ref>" exists then
155`git update-ref` will append a line to the log file
156"$GIT_DIR/logs/<ref>" (dereferencing all symbolic refs before creating
157the log name) describing the change in ref value. Log lines are
158formatted as:
6de08ae6 159
081d9161
AH
160 oldsha1 SP newsha1 SP committer LF
161
6de08ae6
SP
162Where "oldsha1" is the 40 character hexadecimal value previously
163stored in <ref>, "newsha1" is the 40 character hexadecimal value of
67e943c3 164<new-oid> and "committer" is the committer's name, email address
48a8c26c 165and date in the standard Git committer ident format.
6de08ae6
SP
166
167Optionally with -m:
168
081d9161
AH
169 oldsha1 SP newsha1 SP committer TAB message LF
170
6de08ae6
SP
171Where all fields are as described above and "message" is the
172value supplied to the -m option.
173
174An update will fail (without changing <ref>) if the current user is
175unable to create a new log file, append to the existing log file
176or does not have committer information available.
177
12905637
JH
178GIT
179---
9e1f0a85 180Part of the linkgit:git[1] suite