3

What do these HEAD@{0} and HEAD@{1} mean? Isn't HEAD supposed to be a tag pointing to a single commit? Why is it displayed on both then?

git reflog 97df263 HEAD@{0}: commit: I just made my first change to this file. Yay! 4333289 HEAD@{1}: clone: from https://github.com/tswicegood/mysite 
8
  • 2
    Please study the gitrevisions(7) manual which explains all these ~ and ^ funny characters. Commented Aug 7, 2013 at 12:36
  • possible duplicate of What's the difference between ~ and ^ in git Commented Aug 7, 2013 at 12:37
  • @kostix Why? This question has nothing to do with either of those characters. The OP is asking about @{n}. Commented Aug 7, 2013 at 13:14
  • 1
    @Ajedi32, the OP's previous question tagged "git" here on SO was about ~ and ^ in revisions, so actually the OP's problem is that they're not familiar with how Git parses revisions, and the question per se has nothing to do with the reflog (as their previous question had nothing to do with git reset). Commented Aug 7, 2013 at 13:50
  • 2
    See also What does the “at” @ sign/symbol/character mean in Git?. Commented Aug 7, 2013 at 14:11

3 Answers 3

6

HEAD@{1} is the old HEAD, HEAD@{2} is the HEAD before that, and so on.

Example:

$ git reflog abcdefg HEAD@{0}: Initial commit. $ git commit -m "Add new function." [master ab123cd] Add new function. 1 file changed, 15 insertions(+), 2 deletions(-) $ git reflog ab123cd HEAD@{0}: Add new function. abcdefg HEAD@{1}: Initial commit. 
Sign up to request clarification or add additional context in comments.

Comments

3

In the original poster's example:

$ git reflog 97df263 HEAD@{0}: commit: I just made my first change to this file. Yay! 4333289 HEAD@{1}: clone: from https://github.com/tswicegood/mysite 

HEAD@{n} simply means the n-th prior position of HEAD:

  • HEAD@{0} means the 0-th prior position of HEAD.
    • In other words, the current position of HEAD, so HEAD@{0} is actually the same as HEAD.
  • HEAD@{1} means the 1st prior position of HEAD.
  • HEAD@{2} means the 2nd prior position of HEAD, and so on.

More generally, the <reference>@{n} syntax is shorthand to mean "the n-th prior position of the reference/branch", as I state in my answer to What does the “at” @ sign/symbol/character mean in Git?. So you can use this syntax with any reference/branch, for example:

  • master@{1} is the 1st prior position of the master branch.
  • origin/master@{1} is the 1st prior position of the remote-tracking branch origin/master.

As explained in the official Linux Kernel Git documentation for specifying Git revisions:

<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/").

Comments

1

The @{n} part in this case is "how far to go back in history". HEAD@{0} is the most recent value of HEAD and HEAD@{1} is value HEAD had before that most recent value was stored in it. See "SPECIFYING REVISIONS" in the git-rev-parse manual for much more information.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.