Skip to content

Commit c6342e0

Browse files
sivaraamgitster
authored andcommitted
Doc/check-ref-format: clarify information about @{-N} syntax
When the N-th previous thing checked out syntax (@{-N}) is used with '--branch' option of check-ref-format the result may not be the name of a branch that currently exists or ever existed. This is because @{-N} is used to refer to the N-th last checked out "thing", which might be a commit object name if the previous check out was a detached HEAD state; or a branch name, otherwise. The documentation thus does a wrong thing by promoting it as the "previous branch syntax". State that @{-N} is the syntax for specifying "N-th last thing checked out" and also state that the result of using @{-N} might also result in an commit object name. Signed-off-by: Kaartic Sivaraam <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 52015aa commit c6342e0

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

Documentation/git-check-ref-format.txt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,21 @@ reference name expressions (see linkgit:gitrevisions[7]):
7979

8080
With the `--branch` option, the command takes a name and checks if
8181
it can be used as a valid branch name (e.g. when creating a new
82-
branch). The rule `git check-ref-format --branch $name` implements
82+
branch). But be cautious when using the
83+
previous checkout syntax that may refer to a detached HEAD state.
84+
The rule `git check-ref-format --branch $name` implements
8385
may be stricter than what `git check-ref-format refs/heads/$name`
8486
says (e.g. a dash may appear at the beginning of a ref component,
8587
but it is explicitly forbidden at the beginning of a branch name).
8688
When run with `--branch` option in a repository, the input is first
87-
expanded for the ``previous branch syntax''
88-
`@{-n}`. For example, `@{-1}` is a way to refer the last branch you
89-
were on. This option should be used by porcelains to accept this
90-
syntax anywhere a branch name is expected, so they can act as if you
91-
typed the branch name.
89+
expanded for the ``previous checkout syntax''
90+
`@{-n}`. For example, `@{-1}` is a way to refer the last thing that
91+
was checked out using "git checkout" operation. This option should be
92+
used by porcelains to accept this syntax anywhere a branch name is
93+
expected, so they can act as if you typed the branch name. As an
94+
exception note that, the ``previous checkout operation'' might result
95+
in a commit object name when the N-th last thing checked out was not
96+
a branch.
9297

9398
OPTIONS
9499
-------
@@ -116,7 +121,7 @@ OPTIONS
116121
EXAMPLES
117122
--------
118123

119-
* Print the name of the previous branch:
124+
* Print the name of the previous thing checked out:
120125
+
121126
------------
122127
$ git check-ref-format --branch @{-1}

0 commit comments

Comments
 (0)