diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/git/git-update-ref.html | |
new repository
Diffstat (limited to 'devdocs/git/git-update-ref.html')
| -rw-r--r-- | devdocs/git/git-update-ref.html | 23 |
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 <reason>] [--no-deref] (-d <ref> [<oldvalue>] | [--create-reflog] <ref> <newvalue> [<oldvalue>] | --stdin [-z])</pre> </div> </div> <h2 id="_description">Description</h2> <div class="sectionbody"> <p>Given two arguments, stores the <newvalue> in the <ref>, possibly dereferencing the symbolic refs. E.g. <code>git update-ref HEAD +<newvalue></code> updates the current branch head to the new object.</p> <p>Given three arguments, stores the <newvalue> in the <ref>, possibly dereferencing the symbolic refs, after verifying that the current value of the <ref> matches <oldvalue>. E.g. <code>git update-ref refs/heads/master <newvalue> <oldvalue></code> updates the master branch head to <newvalue> only if its current value is <oldvalue>. You can specify 40 "0" or an empty string as <oldvalue> 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, <ref> 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" > "$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 <ref> after verifying it still contains <oldvalue>.</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 <ref> SP <newvalue> [SP <oldvalue>] LF +create SP <ref> SP <newvalue> LF +delete SP <ref> [SP <oldvalue>] LF +verify SP <ref> [SP <oldvalue>] LF +option SP <opt> 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 <ref> NUL <newvalue> NUL [<oldvalue>] NUL +create SP <ref> NUL <newvalue> NUL +delete SP <ref> NUL [<oldvalue>] NUL +verify SP <ref> NUL [<oldvalue>] NUL +option SP <opt> 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 <ref> 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 <ref> to <newvalue> after verifying <oldvalue>, if given. Specify a zero <newvalue> to ensure the ref does not exist after the update and/or a zero <oldvalue> 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 <ref> with <newvalue> after verifying it does not exist. The given <newvalue> may not be zero.</p> </dd> <dt class="hdlist1" id="Documentation/git-update-ref.txt-delete"> delete </dt> <dd> <p>Delete <ref> after verifying it exists with <oldvalue>, if given. If given, <oldvalue> may not be zero.</p> </dd> <dt class="hdlist1" id="Documentation/git-update-ref.txt-verify"> verify </dt> <dd> <p>Verify <ref> against <oldvalue> but do not change it. If <oldvalue> 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 <ref>. 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 <ref>s can be locked with matching <oldvalue>s simultaneously, all modifications are performed. Otherwise, no modifications are performed. Note that while each individual <ref> 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/<ref>" exists then <code>git update-ref</code> will append a line to the log file "$GIT_DIR/logs/<ref>" (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 <ref>, "newsha1" is the 40 character hexadecimal value of <newvalue> 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 <ref>) 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"> + © 2012–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> |
