2

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
cfischer
  • 24,452
  • 37
  • 131
  • 214
  • 2
    Please study the [`gitrevisions(7)` manual](https://www.kernel.org/pub/software/scm/git/docs/gitrevisions.html) which explains all these `~` and `^` funny characters. – kostix Aug 07 '13 at 12:36
  • possible duplicate of [What's the difference between ~ and ^ in git](http://stackoverflow.com/questions/14733687/whats-the-difference-between-and-in-git) – kostix Aug 07 '13 at 12:37
  • @kostix Why? This question has nothing to do with either of those characters. The OP is asking about `@{n}`. – Ajedi32 Aug 07 '13 at 13:14
  • 1
    @Ajedi32, the [OP's previous question tagged "git" here on SO](http://stackoverflow.com/q/18102718/720999) 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`). – kostix Aug 07 '13 at 13:50
  • @Ajedi32 maybe because that same manual page documents the `@{}` syntax... – twalberg Aug 07 '13 at 14:07
  • 2
    See also [What does the “at” @ sign/symbol/character mean in Git?](http://stackoverflow.com/questions/17910096/what-does-the-at-sign-symbol-character-mean-in-git). –  Aug 07 '13 at 14:11
  • @kostix I was questioning why you think this is a duplicate of [What's the difference between ~ and ^ in git](http://stackoverflow.com/q/14733687/1157054), not why you think gitrevisions(7) would be helpful. Sorry for the confusion. – Ajedi32 Aug 07 '13 at 14:21
  • @Ajedi32, there's no confusion ;-) `twalberg` put my idea in a more understandable way (and I failed to convey it properly). I meant that the OP just really asked about the same stuff. So the question can be deemed as duplicate as the OP just really asked about pointers to the right bit of documentation. IMO there's no point in keeping many questions asking about the same stuff different ways, really. – kostix Aug 07 '13 at 15:54

3 Answers3

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.
RazerM
  • 5,128
  • 2
  • 25
  • 34
2

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

Community
  • 1
  • 1
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.

torek
  • 448,244
  • 59
  • 642
  • 775