Skip to content

Commit ea9699e

Browse files
avargitster
authored andcommitted
push doc: correct lies about how push refspecs work
There's complex rules governing whether a push is allowed to take place depending on whether we're pushing to refs/heads/*, refs/tags/* or refs/not-that/*. See is_branch() in refs.c, and the various assertions in refs/files-backend.c. (e.g. "trying to write non-commit object %s to branch '%s'"). This documentation has never been quite correct, but went downhill after dbfeddb ("push: require force for refs under refs/tags/", 2012-11-29) when we started claiming that <dst> couldn't be a tag object, which is incorrect. After some of the logic in that patch was changed in 256b9d7 ("push: fix "refs/tags/ hierarchy cannot be updated without --force"", 2013-01-16) the docs weren't updated, and we've had some version of documentation that confused whether <src> was a tag or not with whether <dst> would accept either an annotated tag object or the commit it points to. This makes the intro somewhat more verbose & complex, perhaps we should have a shorter description here and split the full complexity into a dedicated section. Very few users will find themselves needing to e.g. push blobs or trees to refs/custom-namespace/* (or blobs or trees at all), and that could be covered separately as an advanced topic. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5f9cefa commit ea9699e

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

Documentation/git-push.txt

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ OPTIONS[[OPTIONS]]
6060
by a colon `:`, followed by the destination ref <dst>.
6161
+
6262
The <src> is often the name of the branch you would want to push, but
63-
it can be any arbitrary "SHA-1 expression", such as `master~4` or
64-
`HEAD` (see linkgit:gitrevisions[7]).
63+
it can be any arbitrary "SHA-1 expression" referring to a branch, such
64+
as `master~4` or `HEAD` (see linkgit:gitrevisions[7]). It can also
65+
refer to tag objects, trees or blobs if the <dst> is outside of
66+
`refs/heads/*`.
6567
+
6668
The <dst> tells which ref on the remote side is updated with this
6769
push. Arbitrary expressions cannot be used here, an actual ref must
@@ -74,12 +76,24 @@ without any `<refspec>` on the command line. Otherwise, missing
7476
`:<dst>` means to update the same ref as the `<src>`.
7577
+
7678
The object referenced by <src> is used to update the <dst> reference
77-
on the remote side. By default this is only allowed if <dst> is not
78-
a tag (annotated or lightweight), and then only if it can fast-forward
79-
<dst>. By having the optional leading `+`, you can tell Git to update
80-
the <dst> ref even if it is not allowed by default (e.g., it is not a
81-
fast-forward.) This does *not* attempt to merge <src> into <dst>. See
82-
EXAMPLES below for details.
79+
on the remote side. Whether this is allowed depends on what where in
80+
`refs/*` the <dst> reference lives. The `refs/heads/*` namespace will
81+
only accept commit objects, and then only they can be
82+
fast-forwarded. The `refs/tags/*` namespace will accept any kind of
83+
object, but there commit objects are known as lightweight tags, and
84+
any changes to them and others types of objects will be
85+
rejected. Finally and most confusingly, it's possible to push any type
86+
of object to any namespace outside of `refs/{tags,heads}/*`, but these
87+
will be treated as branches, even in the case where a tag object is
88+
pushed. That tag object will be overwritten by another tag object (or
89+
commit!) without `--force` if the new tag happens to point to a commit
90+
that's a fast-forward of the commit it replaces.
91+
+
92+
By having the optional leading `+`, you can tell Git to update the
93+
<dst> ref even if it is not allowed by its respective namespace
94+
clobbering rules (e.g., it is not a fast-forward. in the case of
95+
`refs/heads/*` updates) This does *not* attempt to merge <src> into
96+
<dst>. See EXAMPLES below for details.
8397
+
8498
`tag <tag>` means the same as `refs/tags/<tag>:refs/tags/<tag>`.
8599
+

Documentation/gitrevisions.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ walk the revision graph (such as linkgit:git-log[1]), all commits which are
1919
reachable from that commit. For commands that walk the revision graph one can
2020
also specify a range of revisions explicitly.
2121

22-
In addition, some Git commands (such as linkgit:git-show[1]) also take
23-
revision parameters which denote other objects than commits, e.g. blobs
24-
("files") or trees ("directories of files").
22+
In addition, some Git commands (such as linkgit:git-show[1] and
23+
linkgit:git-push[1]) can also take revision parameters which denote
24+
other objects than commits, e.g. blobs ("files") or trees
25+
("directories of files").
2526

2627
include::revisions.txt[]
2728

0 commit comments

Comments
 (0)