{"thread":{"id":"34221","subject":"accessing oldest reflog entry with ref@{N}?","startedAt":"2013-06-19T12:50:59Z","lastAt":"2013-06-19T19:41:16Z","messageCount":3,"participants":["SZEDER Gábor","Junio C Hamano","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"221379","messageId":"20130619125059.GD20052@goldbirke","threadId":"34221","inReplyTo":null,"subject":"accessing oldest reflog entry with ref@{N}?","fromName":"SZEDER Gábor","fromEmail":"szeder@ira.uka.de","sentAt":"2013-06-19T12:50:59Z","receivedAt":"2013-06-19T12:50:59Z","isPatch":false,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Hi,\n\nafter a couple of months of inactivity I recently updated my git clone\nfrom the main repo, and later ran 'git gc', which, of course,\ndutifully pruned the old reflog entries, leaving my reflogs quite\nshallow:\n\n$ git reflog master\n0dbd8125 master@{0}: merge origin/master: Fast-forward\nf3828dc0\n\nThen later I had to access the previous state, which I usually do with\nmaster@{1}, but not this time:\n\n$ git log --oneline -1 master@{1}\nfatal: Log for 'master' only has 1 entries.\n\nAnnoyed, I just copy-pasted the sha and got the job done.\n\nHowever, I wonder why it didn't worked.  'git reflog' didn't print\nmaster@{1} or any message for the oldest entry, but I can live without\nthat.  The sha is undoubtedly there, however, so git should know where\nmaster@{1} points and should \"Just Work\", shouldn't it?\n\n\nThanks,\nGábor\n"},{"id":"221395","messageId":"7vk3lqym1q.fsf@alter.siamese.dyndns.org","threadId":"34221","inReplyTo":"20130619125059.GD20052@goldbirke","subject":"Re: accessing oldest reflog entry with ref@{N}?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-06-19T18:48:01Z","receivedAt":"2013-06-19T18:48:01Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"SZEDER Gábor <szeder@ira.uka.de> writes:\n\n> $ git log --oneline -1 master@{1}\n> fatal: Log for 'master' only has 1 entries.\n>\n> Annoyed, I just copy-pasted the sha and got the job done.\n>\n> However, I wonder why it didn't worked. 'git reflog' didn't print\n> master@{1} or any message for the oldest entry, but I can live without\n> that.\n\nThere lies your answer, no?\n\nEach of the log entry records \"this was before, and this is after\nthe change\".  ref@{0} reads from the \"after\" field of 0-th (from the\nend) entry. ref@{1} reads from the \"after\" field of 1-st (again from\nthe end) entry.  ref@{N} reads from the \"after\" field of N-th (again\nfrom the end) entry.\n\nNotice that nowhere in the above sequence we read from \"before\" field.\n"},{"id":"221402","messageId":"20130619194116.GB25160@sigill.intra.peff.net","threadId":"34221","inReplyTo":"7vk3lqym1q.fsf@alter.siamese.dyndns.org","subject":"Re: accessing oldest reflog entry with ref@{N}?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-06-19T19:41:16Z","receivedAt":"2013-06-19T19:41:16Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Jun 19, 2013 at 11:48:01AM -0700, Junio C Hamano wrote:\n\n> SZEDER Gábor <szeder@ira.uka.de> writes:\n> \n> > $ git log --oneline -1 master@{1}\n> > fatal: Log for 'master' only has 1 entries.\n> >\n> > Annoyed, I just copy-pasted the sha and got the job done.\n> >\n> > However, I wonder why it didn't worked. 'git reflog' didn't print\n> > master@{1} or any message for the oldest entry, but I can live without\n> > that.\n> \n> There lies your answer, no?\n> \n> Each of the log entry records \"this was before, and this is after\n> the change\".  ref@{0} reads from the \"after\" field of 0-th (from the\n> end) entry. ref@{1} reads from the \"after\" field of 1-st (again from\n> the end) entry.  ref@{N} reads from the \"after\" field of N-th (again\n> from the end) entry.\n> \n> Notice that nowhere in the above sequence we read from \"before\" field.\n\nIn general, the \"before\" from entry @{N} should be the same as the\n\"after\" of @{N+1}. Of course this is not always the case for various\nreasons, the most common of which I think are:\n\n  1. Buggy scripts which do not provide a reflog reason for their call\n     to git-update-ref, and therefore update the ref without writing a\n     reflog entry.\n\n  2. A git-gc will expire entries which point to unreachable objects\n     much earlier, which can create \"holes\" in the reflog.\n\nSo it is certainly not correct to say \"we do not have a master@{1}\nentry, but we know that the 'before' entry of master@{0} must point to\nthe same thing\". But it is very often a good guess. I wonder if there\nshould be some simple way to expose that value as an @{}-selector.\nPerhaps \"ref@{0.before}\" or something?\n\n-Peff\n"}]}