On Thu, May 02, 2013 at 02:34:01AM +0530, Ramkumar Ramachandra wrote:

> Junio C Hamano wrote:
> > Just making sure.  HEAD@{$n} and @{$n} for non-negative $n mean
> > totally different things.  @{0} and HEAD@{0} are almost always the
> > same, and @{1} and HEAD@{1} may often happen to be the same, but as
> > a blanket statement, I find "Since HEAD is implicit in @{}" very
> > misleading.
> When will they be different?  I'm looking at this from the parser's
> point of view: when the part before @{} is missing, we dwim a "HEAD".

The difference is that HEAD@{} refers to HEAD's reflog, but @{} refers
to the reflog of the branch pointed to by HEAD. For example, try:

  git init repo && cd repo
  git commit --allow-empty -m one &&
  git commit --allow-empty -m two &&
  git checkout HEAD^ &&
  git commit --allow-empty -m three &&
  git checkout master &&
  for i in 0 1 2; do
    echo "HEAD@{$i}: $(git log -1 --oneline HEAD@{$i} 2>&1)"
    echo "    @{$i}: $(git log -1 --oneline     @{$i} 2>&1)"

which produces:

  HEAD@{0}: 1fbb097 two
      @{0}: 1fbb097 two
  HEAD@{1}: 42f3f4d three
      @{1}: 1089d0e one
  HEAD@{2}: 1089d0e one
      @{2}: fatal: Log for '' only has 2 entries.

Unless your reflogs are screwed up, the 0th reflog should always point
to the same commit (since you just moved HEAD there), but beyond that
there is not necessarily any relation. And even for the 0th reflog
entry, the reflog information is not the same. Try this on the repo

  echo "HEAD@{0}: $(git log -g -1 --format='%gd %gs' HEAD@{0})"
  echo "    @{0}: $(git log -g -1 --format='%gd %gs'     @{0})"

which yields:

  HEAD@{0}: HEAD@{0} checkout: moving from ... to master
      @{0}: master@{0} commit: two

To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to