Given two arguments, stores the <newvalue> in the <ref>, possiblydereferencing the symbolic refs. E.g. updates the current branch head to the new object.
Given three arguments, stores the <newvalue> in the <ref>,possibly dereferencing the symbolic refs, after verifying thatthe current value of the <ref> matches <oldvalue>.E.g. git update-ref refs/heads/master <newvalue> <oldvalue>
updates the master branch head to <newvalue> only if its currentvalue is <oldvalue>. You can specify 40 "0" or an empty stringas <oldvalue> to make sure that the ref you are creating doesnot exist.
It also allows a "ref" file to be a symbolic pointer to anotherref file by starting with the four-byte header sequence of"ref:".
More importantly, it allows the update of a ref file to followthese symbolic pointers, whether they are symlinks or these"regular file symbolic refs". It follows real symlinks onlyif they start with "refs/": otherwise it will just try to readthem and update them as a regular file (i.e. it will allow thefilesystem to follow them, but will overwrite such a symlink tosomewhere else with a regular filename).
If —no-deref is given, <ref> itself is overwritten, rather thanthe result of following the symbolic pointers.
In general, using
- git update-ref HEAD "$head"
should be a lot safer than doing
both from a symlink following standpoint and an error checkingstandpoint. The "refs/" rule for symlinks means that symlinksthat point to "outside" the tree are safe: they’ll be followedfor reading but not for writing (so we’ll never write through aref symlink to some other tree, if you have copied a wholearchive by creating a symlink tree).
With flag, it deletes the named <ref> after verifying itstill contains <oldvalue>.
- update SP <ref> SP <newvalue> [SP <oldvalue>] LF
- delete SP <ref> [SP <oldvalue>] LF
- verify SP <ref> [SP <oldvalue>] LF
- option SP <opt> LF
With , update-ref will create a reflog for each refeven if one would not ordinarily be created.
Quote fields containing whitespace as if they were strings in C sourcecode; i.e., surrounded by double-quotes and with backslash escapes.Use 40 "0" characters or the empty string to specify a zero value. Tospecify a missing value, omit the value and its preceding SP entirely.
Alternatively, use -z
to specify in NUL-terminated format, withoutquoting:
In this format, use 40 "0" to specify a zero value, and use the emptystring to specify a missing value.
In either format, values can be specified in any form that Gitrecognizes as an object name. Commands in any other format or arepeated <ref> produce an error. Command meanings are:
- update
delete
Verify against
but do not change it. If zero or missing, the ref must not exist. option
- Modify behavior of the next command naming a .The only valid option is to avoid dereferencinga symbolic ref.
If all <ref>s can be locked with matching <oldvalue>ssimultaneously, all modifications are performed. Otherwise, nomodifications are performed. Note that while each individual<ref> is updated or deleted atomically, a concurrent reader maystill see a subset of the modifications.
If config parameter "core.logAllRefUpdates" is true and the ref is one under"refs/heads/", "refs/remotes/", "refs/notes/", or the symbolic ref HEAD; orthe file "$GIT_DIR/logs/<ref>" exists then git update-ref
will appenda line to the log file "$GIT_DIR/logs/<ref>" (dereferencing allsymbolic refs before creating the log name) describing the changein ref value. Log lines are formatted as:
Where "oldsha1" is the 40 character hexadecimal value previouslystored in <ref>, "newsha1" is the 40 character hexadecimal value of<newvalue> and "committer" is the committer’s name, email addressand date in the standard Git committer ident format.
Optionally with -m:
Where all fields are as described above and "message" is thevalue supplied to the -m option.
An update will fail (without changing <ref>) if the current user isunable to create a new log file, append to the existing log fileor does not have committer information available.