git stash apply stash@{n} contains a number of hard to type characters and repeats some information.

Is there a reason for repeating the stash and using the at-sign and braces instead of something easier to type, like git stash apply n, for instance?

  • I'd like to understand the motivation behind this notation as opposed to one that is more immediately obvious to myself, an outsider who is not very familiar with git. Is there a better way to word the question? Sep 11 '15 at 16:45
  • 1
    I'm voting to reopen this question because, despite being initially worded as "why this exact syntax?" which is technically a subjective opinion poll only the designers can answer, the real question of why it has such an odd, non-obvious syntax is a fair question with an objectively correct answer (as shown below).
    – Ixrec
    Sep 12 '15 at 11:09

This is actually a simple instance of a much more general syntax for specifying symbolic references (basically, all the things in .git/refs). From the current git documentation on revisions:

<refname>@\{<date>\}, e.g. master@{yesterday}, HEAD@\{5 minutes ago\}

A ref followed by the suffix @ with a date specification enclosed in a brace pair (e.g. {yesterday}, {1 month 2 weeks 3 days 1 hour 1 second ago} or {1979-02-26 18:30:00}) specifies the value of the ref at a prior point in time. This suffix may only be used immediately following a ref name and the ref must have an existing log ($GIT_DIR/logs/<ref>). Note that this looks up the state of your local ref at a given time; e.g., what was in your local master branch last week. If you want to look at commits made during certain times, see --since and --until.

<refname>@\{<n>\}, e.g. master@{1}

A ref followed by the suffix @ with an ordinal specification enclosed in a brace pair (e.g. {1}, {15}) specifies the n-th prior value of that ref. For example master@{1} is the immediate prior value of master while master@{5} is the 5th prior value of master. This suffix may only be used immediately following a ref name and the ref must have an existing log ($GIT_DIR/logs/<refname>).

@\{<n>\}, e.g. @{1}

You can use the @ construct with an empty ref part to get at a reflog entry of the current branch. For example, if you are on branch blabla then @{1} means the same as blabla@{1}.

@\{-<n>\}, e.g. @\{-1\}

The construct @\{-<n>\} means the <n>th branch/commit checked out before the current one.

<branchname>@{upstream}, e.g. master@{upstream}, @{u}

The suffix @{upstream} to a branchname (short form @{u}) refers to the branch that the branch specified by branchname is set to build on top of (configured with branch.<name>.remote and branch.<name>.merge). A missing branchname defaults to the current one.

It's very understandable why the stash@{0} syntax would seem unnecessarily ornate if you've only seen it used in the context of stash refs.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.