git-update-ref.txt 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. git-update-ref(1)
  2. =================
  3. NAME
  4. ----
  5. git-update-ref - Update the object name stored in a ref safely
  6. SYNOPSIS
  7. --------
  8. [verse]
  9. 'git update-ref' [-m <reason>] [--no-deref] (-d <ref> [<oldvalue>] | [--create-reflog] <ref> <newvalue> [<oldvalue>] | --stdin [-z])
  10. DESCRIPTION
  11. -----------
  12. Given two arguments, stores the <newvalue> in the <ref>, possibly
  13. dereferencing the symbolic refs. E.g. `git update-ref HEAD
  14. <newvalue>` updates the current branch head to the new object.
  15. Given three arguments, stores the <newvalue> in the <ref>,
  16. possibly dereferencing the symbolic refs, after verifying that
  17. the current value of the <ref> matches <oldvalue>.
  18. E.g. `git update-ref refs/heads/master <newvalue> <oldvalue>`
  19. updates the master branch head to <newvalue> only if its current
  20. value is <oldvalue>. You can specify 40 "0" or an empty string
  21. as <oldvalue> to make sure that the ref you are creating does
  22. not exist.
  23. It also allows a "ref" file to be a symbolic pointer to another
  24. ref file by starting with the four-byte header sequence of
  25. "ref:".
  26. More importantly, it allows the update of a ref file to follow
  27. these symbolic pointers, whether they are symlinks or these
  28. "regular file symbolic refs". It follows *real* symlinks only
  29. if they start with "refs/": otherwise it will just try to read
  30. them and update them as a regular file (i.e. it will allow the
  31. filesystem to follow them, but will overwrite such a symlink to
  32. somewhere else with a regular filename).
  33. If --no-deref is given, <ref> itself is overwritten, rather than
  34. the result of following the symbolic pointers.
  35. In general, using
  36. git update-ref HEAD "$head"
  37. should be a _lot_ safer than doing
  38. echo "$head" > "$GIT_DIR/HEAD"
  39. both from a symlink following standpoint *and* an error checking
  40. standpoint. The "refs/" rule for symlinks means that symlinks
  41. that point to "outside" the tree are safe: they'll be followed
  42. for reading but not for writing (so we'll never write through a
  43. ref symlink to some other tree, if you have copied a whole
  44. archive by creating a symlink tree).
  45. With `-d` flag, it deletes the named <ref> after verifying it
  46. still contains <oldvalue>.
  47. With `--stdin`, update-ref reads instructions from standard input and
  48. performs all modifications together. Specify commands of the form:
  49. update SP <ref> SP <newvalue> [SP <oldvalue>] LF
  50. create SP <ref> SP <newvalue> LF
  51. delete SP <ref> [SP <oldvalue>] LF
  52. verify SP <ref> [SP <oldvalue>] LF
  53. option SP <opt> LF
  54. start LF
  55. prepare LF
  56. commit LF
  57. abort LF
  58. With `--create-reflog`, update-ref will create a reflog for each ref
  59. even if one would not ordinarily be created.
  60. Quote fields containing whitespace as if they were strings in C source
  61. code; i.e., surrounded by double-quotes and with backslash escapes.
  62. Use 40 "0" characters or the empty string to specify a zero value. To
  63. specify a missing value, omit the value and its preceding SP entirely.
  64. Alternatively, use `-z` to specify in NUL-terminated format, without
  65. quoting:
  66. update SP <ref> NUL <newvalue> NUL [<oldvalue>] NUL
  67. create SP <ref> NUL <newvalue> NUL
  68. delete SP <ref> NUL [<oldvalue>] NUL
  69. verify SP <ref> NUL [<oldvalue>] NUL
  70. option SP <opt> NUL
  71. start NUL
  72. prepare NUL
  73. commit NUL
  74. abort NUL
  75. In this format, use 40 "0" to specify a zero value, and use the empty
  76. string to specify a missing value.
  77. In either format, values can be specified in any form that Git
  78. recognizes as an object name. Commands in any other format or a
  79. repeated <ref> produce an error. Command meanings are:
  80. update::
  81. Set <ref> to <newvalue> after verifying <oldvalue>, if given.
  82. Specify a zero <newvalue> to ensure the ref does not exist
  83. after the update and/or a zero <oldvalue> to make sure the
  84. ref does not exist before the update.
  85. create::
  86. Create <ref> with <newvalue> after verifying it does not
  87. exist. The given <newvalue> may not be zero.
  88. delete::
  89. Delete <ref> after verifying it exists with <oldvalue>, if
  90. given. If given, <oldvalue> may not be zero.
  91. verify::
  92. Verify <ref> against <oldvalue> but do not change it. If
  93. <oldvalue> is zero or missing, the ref must not exist.
  94. option::
  95. Modify behavior of the next command naming a <ref>.
  96. The only valid option is `no-deref` to avoid dereferencing
  97. a symbolic ref.
  98. start::
  99. Start a transaction. In contrast to a non-transactional session, a
  100. transaction will automatically abort if the session ends without an
  101. explicit commit.
  102. prepare::
  103. Prepare to commit the transaction. This will create lock files for all
  104. queued reference updates. If one reference could not be locked, the
  105. transaction will be aborted.
  106. commit::
  107. Commit all reference updates queued for the transaction, ending the
  108. transaction.
  109. abort::
  110. Abort the transaction, releasing all locks if the transaction is in
  111. prepared state.
  112. If all <ref>s can be locked with matching <oldvalue>s
  113. simultaneously, all modifications are performed. Otherwise, no
  114. modifications are performed. Note that while each individual
  115. <ref> is updated or deleted atomically, a concurrent reader may
  116. still see a subset of the modifications.
  117. LOGGING UPDATES
  118. ---------------
  119. If config parameter "core.logAllRefUpdates" is true and the ref is one
  120. under "refs/heads/", "refs/remotes/", "refs/notes/", or a pseudoref
  121. like HEAD or ORIG_HEAD; or the file "$GIT_DIR/logs/<ref>" exists then
  122. `git update-ref` will append a line to the log file
  123. "$GIT_DIR/logs/<ref>" (dereferencing all symbolic refs before creating
  124. the log name) describing the change in ref value. Log lines are
  125. formatted as:
  126. oldsha1 SP newsha1 SP committer LF
  127. Where "oldsha1" is the 40 character hexadecimal value previously
  128. stored in <ref>, "newsha1" is the 40 character hexadecimal value of
  129. <newvalue> and "committer" is the committer's name, email address
  130. and date in the standard Git committer ident format.
  131. Optionally with -m:
  132. oldsha1 SP newsha1 SP committer TAB message LF
  133. Where all fields are as described above and "message" is the
  134. value supplied to the -m option.
  135. An update will fail (without changing <ref>) if the current user is
  136. unable to create a new log file, append to the existing log file
  137. or does not have committer information available.
  138. GIT
  139. ---
  140. Part of the linkgit:git[1] suite