Fixed issue #4133: libgit2 returned: failed to parse revision specifier (ref ending...
[TortoiseGit.git] / doc / source / en / TortoiseGit / git_doc / git-update-ref.xml
blobea41dea41b81a94ceb1ab4fc9b86f124fca74292
1 <?xml version="1.0" encoding="UTF-8"?>\r
2 <!DOCTYPE sect2 SYSTEM "../../../dtd/dblite.dtd">\r
3 \r
4 <sect2 lang="en" id="git-update-ref(1)">\r
5     <title>git-update-ref(1)</title>\r
6     <date>2023-11-02</date>\r
7 <revhistory><revision><date>2023-11-02</date></revision></revhistory>\r
8 <indexterm>\r
9 <primary>git-update-ref(1)</primary>\r
10 </indexterm>\r
11 <simplesect id="git-update-ref(1)__name">\r
12 <title>NAME</title>\r
13 <simpara>git-update-ref - Update the object name stored in a ref safely</simpara>\r
14 </simplesect>\r
15 <simplesect id="git-update-ref(1)__synopsis">\r
16 <title>SYNOPSIS</title>\r
17 <blockquote>\r
18 <literallayout><emphasis>git update-ref</emphasis> [-m &lt;reason&gt;] [--no-deref] (-d &lt;ref&gt; [&lt;oldvalue&gt;] | [--create-reflog] &lt;ref&gt; &lt;newvalue&gt; [&lt;oldvalue&gt;] | --stdin [-z])</literallayout>\r
19 </blockquote>\r
20 </simplesect>\r
21 <simplesect id="git-update-ref(1)__description">\r
22 <title>DESCRIPTION</title>\r
23 <simpara>Given two arguments, stores the &lt;newvalue&gt; in the &lt;ref&gt;, possibly\r
24 dereferencing the symbolic refs.  E.g. <emphasis>git update-ref HEAD\r
25 &lt;newvalue&gt;</emphasis> updates the current branch head to the new object.</simpara>\r
26 <simpara>Given three arguments, stores the &lt;newvalue&gt; in the &lt;ref&gt;,\r
27 possibly dereferencing the symbolic refs, after verifying that\r
28 the current value of the &lt;ref&gt; matches &lt;oldvalue&gt;.\r
29 E.g. <emphasis>git update-ref refs/heads/master &lt;newvalue&gt; &lt;oldvalue&gt;</emphasis>\r
30 updates the master branch head to &lt;newvalue&gt; only if its current\r
31 value is &lt;oldvalue&gt;.  You can specify 40 "0" or an empty string\r
32 as &lt;oldvalue&gt; to make sure that the ref you are creating does\r
33 not exist.</simpara>\r
34 <simpara>It also allows a "ref" file to be a symbolic pointer to another\r
35 ref file by starting with the four-byte header sequence of\r
36 "ref:".</simpara>\r
37 <simpara>More importantly, it allows the update of a ref file to follow\r
38 these symbolic pointers, whether they are symlinks or these\r
39 "regular file symbolic refs".  It follows <emphasis role="strong">real</emphasis> symlinks only\r
40 if they start with "refs/": otherwise it will just try to read\r
41 them and update them as a regular file (i.e. it will allow the\r
42 filesystem to follow them, but will overwrite such a symlink to\r
43 somewhere else with a regular filename).</simpara>\r
44 <simpara>If --no-deref is given, &lt;ref&gt; itself is overwritten, rather than\r
45 the result of following the symbolic pointers.</simpara>\r
46 <simpara>In general, using</simpara>\r
47 <literallayout class="monospaced">git update-ref HEAD "$head"</literallayout>\r
48 <simpara>should be a <emphasis>lot</emphasis> safer than doing</simpara>\r
49 <literallayout class="monospaced">echo "$head" &gt; "$GIT_DIR/HEAD"</literallayout>\r
50 <simpara>both from a symlink following standpoint <emphasis role="strong">and</emphasis> an error checking\r
51 standpoint.  The "refs/" rule for symlinks means that symlinks\r
52 that point to "outside" the tree are safe: they'll be followed\r
53 for reading but not for writing (so we'll never write through a\r
54 ref symlink to some other tree, if you have copied a whole\r
55 archive by creating a symlink tree).</simpara>\r
56 <simpara>With <emphasis>-d</emphasis> flag, it deletes the named &lt;ref&gt; after verifying it\r
57 still contains &lt;oldvalue&gt;.</simpara>\r
58 <simpara>With <emphasis>--stdin</emphasis>, update-ref reads instructions from standard input and\r
59 performs all modifications together.  Specify commands of the form:</simpara>\r
60 <literallayout class="monospaced">update SP &lt;ref&gt; SP &lt;newvalue&gt; [SP &lt;oldvalue&gt;] LF\r
61 create SP &lt;ref&gt; SP &lt;newvalue&gt; LF\r
62 delete SP &lt;ref&gt; [SP &lt;oldvalue&gt;] LF\r
63 verify SP &lt;ref&gt; [SP &lt;oldvalue&gt;] LF\r
64 option SP &lt;opt&gt; LF\r
65 start LF\r
66 prepare LF\r
67 commit LF\r
68 abort LF</literallayout>\r
69 <simpara>With <emphasis>--create-reflog</emphasis>, update-ref will create a reflog for each ref\r
70 even if one would not ordinarily be created.</simpara>\r
71 <simpara>Quote fields containing whitespace as if they were strings in C source\r
72 code; i.e., surrounded by double-quotes and with backslash escapes.\r
73 Use 40 "0" characters or the empty string to specify a zero value.  To\r
74 specify a missing value, omit the value and its preceding SP entirely.</simpara>\r
75 <simpara>Alternatively, use <emphasis>-z</emphasis> to specify in NUL-terminated format, without\r
76 quoting:</simpara>\r
77 <literallayout class="monospaced">update SP &lt;ref&gt; NUL &lt;newvalue&gt; NUL [&lt;oldvalue&gt;] NUL\r
78 create SP &lt;ref&gt; NUL &lt;newvalue&gt; NUL\r
79 delete SP &lt;ref&gt; NUL [&lt;oldvalue&gt;] NUL\r
80 verify SP &lt;ref&gt; NUL [&lt;oldvalue&gt;] NUL\r
81 option SP &lt;opt&gt; NUL\r
82 start NUL\r
83 prepare NUL\r
84 commit NUL\r
85 abort NUL</literallayout>\r
86 <simpara>In this format, use 40 "0" to specify a zero value, and use the empty\r
87 string to specify a missing value.</simpara>\r
88 <simpara>In either format, values can be specified in any form that Git\r
89 recognizes as an object name.  Commands in any other format or a\r
90 repeated &lt;ref&gt; produce an error.  Command meanings are:</simpara>\r
91 <variablelist>\r
92 <varlistentry>\r
93 <term>\r
94 update\r
95 </term>\r
96 <listitem>\r
97 <simpara>\r
98         Set &lt;ref&gt; to &lt;newvalue&gt; after verifying &lt;oldvalue&gt;, if given.\r
99         Specify a zero &lt;newvalue&gt; to ensure the ref does not exist\r
100         after the update and/or a zero &lt;oldvalue&gt; to make sure the\r
101         ref does not exist before the update.\r
102 </simpara>\r
103 </listitem>\r
104 </varlistentry>\r
105 <varlistentry>\r
106 <term>\r
107 create\r
108 </term>\r
109 <listitem>\r
110 <simpara>\r
111         Create &lt;ref&gt; with &lt;newvalue&gt; after verifying it does not\r
112         exist.  The given &lt;newvalue&gt; may not be zero.\r
113 </simpara>\r
114 </listitem>\r
115 </varlistentry>\r
116 <varlistentry>\r
117 <term>\r
118 delete\r
119 </term>\r
120 <listitem>\r
121 <simpara>\r
122         Delete &lt;ref&gt; after verifying it exists with &lt;oldvalue&gt;, if\r
123         given.  If given, &lt;oldvalue&gt; may not be zero.\r
124 </simpara>\r
125 </listitem>\r
126 </varlistentry>\r
127 <varlistentry>\r
128 <term>\r
129 verify\r
130 </term>\r
131 <listitem>\r
132 <simpara>\r
133         Verify &lt;ref&gt; against &lt;oldvalue&gt; but do not change it.  If\r
134         &lt;oldvalue&gt; is zero or missing, the ref must not exist.\r
135 </simpara>\r
136 </listitem>\r
137 </varlistentry>\r
138 <varlistentry>\r
139 <term>\r
140 option\r
141 </term>\r
142 <listitem>\r
143 <simpara>\r
144         Modify behavior of the next command naming a &lt;ref&gt;.\r
145         The only valid option is <emphasis>no-deref</emphasis> to avoid dereferencing\r
146         a symbolic ref.\r
147 </simpara>\r
148 </listitem>\r
149 </varlistentry>\r
150 <varlistentry>\r
151 <term>\r
152 start\r
153 </term>\r
154 <listitem>\r
155 <simpara>\r
156         Start a transaction. In contrast to a non-transactional session, a\r
157         transaction will automatically abort if the session ends without an\r
158         explicit commit. This command may create a new empty transaction when\r
159         the current one has been committed or aborted already.\r
160 </simpara>\r
161 </listitem>\r
162 </varlistentry>\r
163 <varlistentry>\r
164 <term>\r
165 prepare\r
166 </term>\r
167 <listitem>\r
168 <simpara>\r
169         Prepare to commit the transaction. This will create lock files for all\r
170         queued reference updates. If one reference could not be locked, the\r
171         transaction will be aborted.\r
172 </simpara>\r
173 </listitem>\r
174 </varlistentry>\r
175 <varlistentry>\r
176 <term>\r
177 commit\r
178 </term>\r
179 <listitem>\r
180 <simpara>\r
181         Commit all reference updates queued for the transaction, ending the\r
182         transaction.\r
183 </simpara>\r
184 </listitem>\r
185 </varlistentry>\r
186 <varlistentry>\r
187 <term>\r
188 abort\r
189 </term>\r
190 <listitem>\r
191 <simpara>\r
192         Abort the transaction, releasing all locks if the transaction is in\r
193         prepared state.\r
194 </simpara>\r
195 </listitem>\r
196 </varlistentry>\r
197 </variablelist>\r
198 <simpara>If all &lt;ref&gt;s can be locked with matching &lt;oldvalue&gt;s\r
199 simultaneously, all modifications are performed.  Otherwise, no\r
200 modifications are performed.  Note that while each individual\r
201 &lt;ref&gt; is updated or deleted atomically, a concurrent reader may\r
202 still see a subset of the modifications.</simpara>\r
203 </simplesect>\r
204 <simplesect id="git-update-ref(1)__logging_updates">\r
205 <title>LOGGING UPDATES</title>\r
206 <simpara>If config parameter "core.logAllRefUpdates" is true and the ref is one\r
207 under "refs/heads/", "refs/remotes/", "refs/notes/", or a pseudoref\r
208 like HEAD or ORIG_HEAD; or the file "$GIT_DIR/logs/&lt;ref&gt;" exists then\r
209 <emphasis>git update-ref</emphasis> will append a line to the log file\r
210 "$GIT_DIR/logs/&lt;ref&gt;" (dereferencing all symbolic refs before creating\r
211 the log name) describing the change in ref value.  Log lines are\r
212 formatted as:</simpara>\r
213 <literallayout class="monospaced">oldsha1 SP newsha1 SP committer LF</literallayout>\r
214 <simpara>Where "oldsha1" is the 40 character hexadecimal value previously\r
215 stored in &lt;ref&gt;, "newsha1" is the 40 character hexadecimal value of\r
216 &lt;newvalue&gt; and "committer" is the committer's name, email address\r
217 and date in the standard Git committer ident format.</simpara>\r
218 <simpara>Optionally with -m:</simpara>\r
219 <literallayout class="monospaced">oldsha1 SP newsha1 SP committer TAB message LF</literallayout>\r
220 <simpara>Where all fields are as described above and "message" is the\r
221 value supplied to the -m option.</simpara>\r
222 <simpara>An update will fail (without changing &lt;ref&gt;) if the current user is\r
223 unable to create a new log file, append to the existing log file\r
224 or does not have committer information available.</simpara>\r
225 </simplesect>\r
226 <simplesect id="git-update-ref(1)__git">\r
227 <title>GIT</title>\r
228 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>\r
229 </simplesect>\r
230 </sect2>\r