blob: d377a352433cb38536f42c5b3fc6b80ae2b11f7f [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231git-update-ref(1)
2=================
3
4NAME
5----
Junio C Hamano7c73c662007-01-19 00:37:506git-update-ref - Update the object name stored in a ref safely
Junio C Hamano1a4e8412005-12-27 08:17:237
8SYNOPSIS
9--------
Junio C Hamano15567bc2011-07-23 00:51:5910[verse]
Junio C Hamanofce7c7e2008-07-02 03:06:3811'git update-ref' [-m <reason>] (-d <ref> [<oldvalue>] | [--no-deref] <ref> <newvalue> [<oldvalue>])
Junio C Hamano1a4e8412005-12-27 08:17:2312
13DESCRIPTION
14-----------
15Given two arguments, stores the <newvalue> in the <ref>, possibly
Junio C Hamanofce7c7e2008-07-02 03:06:3816dereferencing the symbolic refs. E.g. `git update-ref HEAD
Junio C Hamano1a4e8412005-12-27 08:17:2317<newvalue>` updates the current branch head to the new object.
18
19Given three arguments, stores the <newvalue> in the <ref>,
20possibly dereferencing the symbolic refs, after verifying that
21the current value of the <ref> matches <oldvalue>.
Junio C Hamanofce7c7e2008-07-02 03:06:3822E.g. `git update-ref refs/heads/master <newvalue> <oldvalue>`
Junio C Hamano1a4e8412005-12-27 08:17:2323updates the master branch head to <newvalue> only if its current
Junio C Hamanoa2ec14f2006-11-02 00:22:4824value is <oldvalue>. You can specify 40 "0" or an empty string
25as <oldvalue> to make sure that the ref you are creating does
26not exist.
Junio C Hamano1a4e8412005-12-27 08:17:2327
28It also allows a "ref" file to be a symbolic pointer to another
29ref file by starting with the four-byte header sequence of
30"ref:".
31
32More importantly, it allows the update of a ref file to follow
33these symbolic pointers, whether they are symlinks or these
34"regular file symbolic refs". It follows *real* symlinks only
35if they start with "refs/": otherwise it will just try to read
36them and update them as a regular file (i.e. it will allow the
37filesystem to follow them, but will overwrite such a symlink to
38somewhere else with a regular filename).
39
Junio C Hamanof2ce2972007-05-20 19:12:0940If --no-deref is given, <ref> itself is overwritten, rather than
41the result of following the symbolic pointers.
42
Junio C Hamano1a4e8412005-12-27 08:17:2343In general, using
44
Junio C Hamanofce7c7e2008-07-02 03:06:3845git update-ref HEAD "$head"
Junio C Hamano1a4e8412005-12-27 08:17:2346
47should be a _lot_ safer than doing
48
49echo "$head" > "$GIT_DIR/HEAD"
50
51both from a symlink following standpoint *and* an error checking
52standpoint. The "refs/" rule for symlinks means that symlinks
53that point to "outside" the tree are safe: they'll be followed
54for reading but not for writing (so we'll never write through a
55ref symlink to some other tree, if you have copied a whole
56archive by creating a symlink tree).
57
Junio C Hamanoa2ec14f2006-11-02 00:22:4858With `-d` flag, it deletes the named <ref> after verifying it
59still contains <oldvalue>.
60
61
Junio C Hamano341071d2006-06-04 07:24:4862Logging Updates
63---------------
Junio C Hamano15567bc2011-07-23 00:51:5964If config parameter "core.logAllRefUpdates" is true and the ref is one under
65"refs/heads/", "refs/remotes/", "refs/notes/", or the symbolic ref HEAD; or
66the file "$GIT_DIR/logs/<ref>" exists then `git update-ref` will append
Junio C Hamano341071d2006-06-04 07:24:4867a line to the log file "$GIT_DIR/logs/<ref>" (dereferencing all
68symbolic refs before creating the log name) describing the change
69in ref value. Log lines are formatted as:
70
71 . oldsha1 SP newsha1 SP committer LF
72+
73Where "oldsha1" is the 40 character hexadecimal value previously
74stored in <ref>, "newsha1" is the 40 character hexadecimal value of
75<newvalue> and "committer" is the committer's name, email address
76and date in the standard GIT committer ident format.
77
78Optionally with -m:
79
80 . oldsha1 SP newsha1 SP committer TAB message LF
81+
82Where all fields are as described above and "message" is the
83value supplied to the -m option.
84
85An update will fail (without changing <ref>) if the current user is
86unable to create a new log file, append to the existing log file
87or does not have committer information available.
88
Junio C Hamano1a4e8412005-12-27 08:17:2389GIT
90---
Junio C Hamanof7c042d2008-06-06 22:50:5391Part of the linkgit:git[1] suite