summaryrefslogtreecommitdiff
path: root/devdocs/git/git-update-ref.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/git/git-update-ref.html')
-rw-r--r--devdocs/git/git-update-ref.html23
1 files changed, 23 insertions, 0 deletions
diff --git a/devdocs/git/git-update-ref.html b/devdocs/git/git-update-ref.html
new file mode 100644
index 00000000..34639cf2
--- /dev/null
+++ b/devdocs/git/git-update-ref.html
@@ -0,0 +1,23 @@
+<h1>git-update-ref</h1> <h2 id="_name">Name</h2> <div class="sectionbody"> <p>git-update-ref - Update the object name stored in a ref safely</p> </div> <h2 id="_synopsis">Synopsis</h2> <div class="sectionbody"> <div class="verseblock"> <pre class="content" data-language="shell">git update-ref [-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])</pre> </div> </div> <h2 id="_description">Description</h2> <div class="sectionbody"> <p>Given two arguments, stores the &lt;newvalue&gt; in the &lt;ref&gt;, possibly dereferencing the symbolic refs. E.g. <code>git update-ref HEAD
+&lt;newvalue&gt;</code> updates the current branch head to the new object.</p> <p>Given three arguments, stores the &lt;newvalue&gt; in the &lt;ref&gt;, possibly dereferencing the symbolic refs, after verifying that the current value of the &lt;ref&gt; matches &lt;oldvalue&gt;. E.g. <code>git update-ref refs/heads/master &lt;newvalue&gt; &lt;oldvalue&gt;</code> updates the master branch head to &lt;newvalue&gt; only if its current value is &lt;oldvalue&gt;. You can specify 40 "0" or an empty string as &lt;oldvalue&gt; to make sure that the ref you are creating does not exist.</p> <p>It also allows a "ref" file to be a symbolic pointer to another ref file by starting with the four-byte header sequence of "ref:".</p> <p>More importantly, it allows the update of a ref file to follow these symbolic pointers, whether they are symlinks or these "regular file symbolic refs". It follows <strong>real</strong> symlinks only if they start with "refs/": otherwise it will just try to read them and update them as a regular file (i.e. it will allow the filesystem to follow them, but will overwrite such a symlink to somewhere else with a regular filename).</p> <p>If --no-deref is given, &lt;ref&gt; itself is overwritten, rather than the result of following the symbolic pointers.</p> <p>In general, using</p> <div class="literalblock"> <div class="content"> <pre data-language="shell">git update-ref HEAD "$head"</pre> </div> </div> <p>should be a <code>lot</code> safer than doing</p> <div class="literalblock"> <div class="content"> <pre>echo "$head" &gt; "$GIT_DIR/HEAD"</pre> </div> </div> <p>both from a symlink following standpoint <strong>and</strong> an error checking standpoint. The "refs/" rule for symlinks means that symlinks that point to "outside" the tree are safe: they’ll be followed for reading but not for writing (so we’ll never write through a ref symlink to some other tree, if you have copied a whole archive by creating a symlink tree).</p> <p>With <code>-d</code> flag, it deletes the named &lt;ref&gt; after verifying it still contains &lt;oldvalue&gt;.</p> <p>With <code>--stdin</code>, update-ref reads instructions from standard input and performs all modifications together. Specify commands of the form:</p> <div class="literalblock"> <div class="content"> <pre>update SP &lt;ref&gt; SP &lt;newvalue&gt; [SP &lt;oldvalue&gt;] LF
+create SP &lt;ref&gt; SP &lt;newvalue&gt; LF
+delete SP &lt;ref&gt; [SP &lt;oldvalue&gt;] LF
+verify SP &lt;ref&gt; [SP &lt;oldvalue&gt;] LF
+option SP &lt;opt&gt; LF
+start LF
+prepare LF
+commit LF
+abort LF</pre> </div> </div> <p>With <code>--create-reflog</code>, update-ref will create a reflog for each ref even if one would not ordinarily be created.</p> <p>Quote fields containing whitespace as if they were strings in C source code; i.e., surrounded by double-quotes and with backslash escapes. Use 40 "0" characters or the empty string to specify a zero value. To specify a missing value, omit the value and its preceding SP entirely.</p> <p>Alternatively, use <code>-z</code> to specify in NUL-terminated format, without quoting:</p> <div class="literalblock"> <div class="content"> <pre>update SP &lt;ref&gt; NUL &lt;newvalue&gt; NUL [&lt;oldvalue&gt;] NUL
+create SP &lt;ref&gt; NUL &lt;newvalue&gt; NUL
+delete SP &lt;ref&gt; NUL [&lt;oldvalue&gt;] NUL
+verify SP &lt;ref&gt; NUL [&lt;oldvalue&gt;] NUL
+option SP &lt;opt&gt; NUL
+start NUL
+prepare NUL
+commit NUL
+abort NUL</pre> </div> </div> <p>In this format, use 40 "0" to specify a zero value, and use the empty string to specify a missing value.</p> <p>In either format, values can be specified in any form that Git recognizes as an object name. Commands in any other format or a repeated &lt;ref&gt; produce an error. Command meanings are:</p> <div class="dlist"> <dl> <dt class="hdlist1" id="Documentation/git-update-ref.txt-update"> update </dt> <dd> <p>Set &lt;ref&gt; to &lt;newvalue&gt; after verifying &lt;oldvalue&gt;, if given. Specify a zero &lt;newvalue&gt; to ensure the ref does not exist after the update and/or a zero &lt;oldvalue&gt; to make sure the ref does not exist before the update.</p> </dd> <dt class="hdlist1" id="Documentation/git-update-ref.txt-create"> create </dt> <dd> <p>Create &lt;ref&gt; with &lt;newvalue&gt; after verifying it does not exist. The given &lt;newvalue&gt; may not be zero.</p> </dd> <dt class="hdlist1" id="Documentation/git-update-ref.txt-delete"> delete </dt> <dd> <p>Delete &lt;ref&gt; after verifying it exists with &lt;oldvalue&gt;, if given. If given, &lt;oldvalue&gt; may not be zero.</p> </dd> <dt class="hdlist1" id="Documentation/git-update-ref.txt-verify"> verify </dt> <dd> <p>Verify &lt;ref&gt; against &lt;oldvalue&gt; but do not change it. If &lt;oldvalue&gt; is zero or missing, the ref must not exist.</p> </dd> <dt class="hdlist1" id="Documentation/git-update-ref.txt-option"> option </dt> <dd> <p>Modify the behavior of the next command naming a &lt;ref&gt;. The only valid option is <code>no-deref</code> to avoid dereferencing a symbolic ref.</p> </dd> <dt class="hdlist1" id="Documentation/git-update-ref.txt-start"> start </dt> <dd> <p>Start a transaction. In contrast to a non-transactional session, a transaction will automatically abort if the session ends without an explicit commit. This command may create a new empty transaction when the current one has been committed or aborted already.</p> </dd> <dt class="hdlist1" id="Documentation/git-update-ref.txt-prepare"> prepare </dt> <dd> <p>Prepare to commit the transaction. This will create lock files for all queued reference updates. If one reference could not be locked, the transaction will be aborted.</p> </dd> <dt class="hdlist1" id="Documentation/git-update-ref.txt-commit"> commit </dt> <dd> <p>Commit all reference updates queued for the transaction, ending the transaction.</p> </dd> <dt class="hdlist1" id="Documentation/git-update-ref.txt-abort"> abort </dt> <dd> <p>Abort the transaction, releasing all locks if the transaction is in prepared state.</p> </dd> </dl> </div> <p>If all &lt;ref&gt;s can be locked with matching &lt;oldvalue&gt;s simultaneously, all modifications are performed. Otherwise, no modifications are performed. Note that while each individual &lt;ref&gt; is updated or deleted atomically, a concurrent reader may still see a subset of the modifications.</p> </div> <h2 id="_logging_updates">Logging updates</h2> <div class="sectionbody"> <p>If config parameter "core.logAllRefUpdates" is true and the ref is one under "refs/heads/", "refs/remotes/", "refs/notes/", or a pseudoref like HEAD or ORIG_HEAD; or the file "$GIT_DIR/logs/&lt;ref&gt;" exists then <code>git update-ref</code> will append a line to the log file "$GIT_DIR/logs/&lt;ref&gt;" (dereferencing all symbolic refs before creating the log name) describing the change in ref value. Log lines are formatted as:</p> <div class="literalblock"> <div class="content"> <pre>oldsha1 SP newsha1 SP committer LF</pre> </div> </div> <p>Where "oldsha1" is the 40 character hexadecimal value previously stored in &lt;ref&gt;, "newsha1" is the 40 character hexadecimal value of &lt;newvalue&gt; and "committer" is the committer’s name, email address and date in the standard Git committer ident format.</p> <p>Optionally with -m:</p> <div class="literalblock"> <div class="content"> <pre>oldsha1 SP newsha1 SP committer TAB message LF</pre> </div> </div> <p>Where all fields are as described above and "message" is the value supplied to the -m option.</p> <p>An update will fail (without changing &lt;ref&gt;) if the current user is unable to create a new log file, append to the existing log file or does not have committer information available.</p> </div><div class="_attribution">
+ <p class="_attribution-p">
+ &copy; 2012&ndash;2024 Scott Chacon and others<br>Licensed under the MIT License.<br>
+ <a href="https://git-scm.com/docs/git-update-ref" class="_attribution-link">https://git-scm.com/docs/git-update-ref</a>
+ </p>
+</div>