git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 3/7] Documentation: rework SHA1 description in git push

From
Junio C Hamano <gitster@pobox.com>
Date
Oct 31, 2008, 05:36 UTC
Message-ID
<7v1vxxba2c.fsf@gitster.siamese.dyndns.org>
In-Reply-To
<1225311945-17100-4-git-send-email-mail@cup.kalibalik.dk>
Anders Melchiorsen <mail@cup.kalibalik.dk> writes:
> Get rid of a double pair of parentheses. The arbitrary SHA1 is a
> special case, so it can be postponed a bit.
Hmmm...

Strictly speaking, arbitrary SHA-1 is the general case, and branch name is a special case of it, but in practice, branch name is the most frequently used form, and that is why it has the short-hand convention that allows it to to be pushed to the same name. I agree with the outcome of this patch (except for one point I'll mention shortly) because I think it is a good idea to talk about most frequently used form first, not because "branch" is the general case. IOW, the proposed commit log message is wrong.

> Also mention HEAD, which is possibly the most useful SHA1 in this
> situation.

HEAD is indeed useful, but it falls into the special case of "branch name", not "arbitrary SHA-1 expression". This distinction is important because you can push "HEAD" without colon and it will act as if you said master:master (or whatever branch you are currently on). This is already described in the existing doc:

    The local ref that matches <src> is used
    to fast forward the remote ref that matches <dst> (or, if no <dst> was
    specified, the same ref that <src> referred to locally).

but I agree that it is unnecessarily hard to understand, because the document tries to describe the general case first and then relies on the user to understand that "ref <src> referred to locally" means "branch name". We should make this part more explicit.

With that in mind, I have two paragraphs to replace the parts your patch touches as a counterproposal.

Show 13 quoted lines
> diff --git a/Documentation/git-push.txt b/Documentation/git-push.txt
> index 02c7dae..fb9fb97 100644
> --- a/Documentation/git-push.txt
> +++ b/Documentation/git-push.txt
> @@ -38,9 +38,7 @@ OPTIONS
>  	by the source ref, followed by a colon `:`, followed by
>  	the destination ref.
>  +
> -The <src> side represents the source branch (or arbitrary
> -"SHA1 expression", such as `master~4` (four parents before the
> -tip of `master` branch); see linkgit:git-rev-parse[1]) that you
> +The <src> side represents the source branch that you
>  want to push.  The <dst> side represents the destination location.

The <src> is often the name of the branch you would want to push, but it can be any arbitrary "SHA-1 expression", such as `master~4` (four parents before the tip of `master` branch -- see linkgit:git-rev-parse[1]), or `HEAD` (the tip of the current branch). The <dst> tells which ref on the remote side is updated with this push.

The object referenced by <src> is used to fast forward the ref <dst> on the remote side. You can omit <dst> to update the same ref on the remote side as <src> (<src> is often the name of a branch you push, and often you push to the same branch on the remote side; `git push HEAD` is a handy way to push only the current branch to the remote side under the same name). If the optional leading plus `{plus}` is used, the remote ref is updated even if it does not result in a fast forward update.

Show 8 quoted lines
> @@ -193,6 +195,10 @@ git push origin master::
>  	with it.  If `master` did not exist remotely, it would be
>  	created.
>  
> +git push origin HEAD:master::
> +	Push the current head to the remote ref matching `master` in
> +	the `origin` repository.
> +

Additional example is good, but you would want to tell readers that this would be useful when your current branch is _not_ 'master'.

Previous: Daniel BarkalowNext: Anders Melchiorsen
Message 10 of 15 in “Some updates to refspec documentation”
  1. Anders MelchiorsenOct 29, 2008
  2. 1/7 Documentation: do not use regexp in refspec descriptionsAnders Melchiorsen, Oct 29, 2008
  3. 2/7 Documentation: git push repository can also be a remoteAnders Melchiorsen, Oct 29, 2008
  4. 3/7 Documentation: rework SHA1 description in git pushAnders Melchiorsen, Oct 29, 2008
  5. 4/7 Documentation: remove a redundant elaborationAnders Melchiorsen, Oct 29, 2008
  6. 5/7 Documentation: elaborate on pushing tagsAnders Melchiorsen, Oct 29, 2008
  7. 6/7 Documentation: mention branches rather than headsAnders Melchiorsen, Oct 29, 2008
  8. 7/7 Documentation: avoid using undefined parametersAnders Melchiorsen, Oct 29, 2008
  9. Daniel BarkalowOct 29, 2008
  10. Junio C HamanoOct 31, 2008
  11. Anders MelchiorsenNov 2, 2008
  12. Junio C HamanoOct 31, 2008
  13. Anders MelchiorsenNov 2, 2008
  14. Anders MelchiorsenOct 29, 2008
  15. Anders MelchiorsenOct 29, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.