git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Annoyance wrt ref@{1} and reflog expiry

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 19, 2020, 20:31 UTC
Message-ID
<xmqqwo42g5ld.fsf@gitster.c.googlers.com>
In-Reply-To
<87o8pe3ou6.fsf@osv.gnss.ru>
Sergey Organov <sorganov@gmail.com> writes:
Show 12 quoted lines
>> But then if you do
>>
>>     $ git reflog expire --expire=now refs/heads/newbranch
>>     $ git commit --allow=empty -m two
>>     $ git show -s newbranch@{1}
>> ...
>> And it is unintuitive.  It is understandable to the users that all
>> the ref history before "reflog expire" is lost---it was what the end
>> user asked Git to do.  But after creating one commit on the state
>> (or do anything else that moves the ref) and finding it regrettable,
>> "git reset --hard @{1}" should be a viable way to recover from the
>> mistake made _after_ the reflog entries were expired.

And the expiration does not have to be --expire=now; what happens more often is when I expire entries older than (say) a week, the reflog for a topic branch that hasn't seen any activity may become empty. Then I "git am" the new round on the same base, compare and then update, perhaps like so:

    ... git reflog expire has emptied the log for so/topic ...
    $ git checkout so/topic
    $ git log master.. ;# remind myself what the previous round had
    $ git checkout master... ;# detach HEAD at the previous base
    $ git am -s ./+so-v2-topic ;# apply
    $ git range-diff @{-1}... ;# compare
    $ git checkout -B so/topic
Now, I'm used to see this work after the above:
    $ git range-diff @{1}... ;# compare again just to be sure

but because there is only one entry in the reflog, which was created when the last "checkout -B" updated the so/topic branch, "there is only one entry" error kicks in.

> Makes sense. The first solution that comes to mind is immediately record
> current state after "reflog expire", so that there will be 2 entries for
> the case in question.
Perhaps.  

Or we could change the lookup side to use the value of the ref itself when asked for @{0}, and use the "old" side of the only entry when asked for @{1}. That way, we do not need to play games with an artificial entry at all, which may be a better solution.

I dunno.
Previous: Sergey OrganovNext: Junio C Hamano
Message 3 of 6 in “Annoyance wrt ref@{1} and reflog expiry”
  1. Junio C HamanoJun 19, 2020
  2. Sergey OrganovJun 19, 2020
  3. Junio C HamanoJun 19, 2020
  4. Junio C HamanoJun 19, 2020
  5. Mike HommeyJun 19, 2020
  6. Junio C HamanoJun 19, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.