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

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

From
Sergey Organov <sorganov@gmail.com>
Date
Jun 19, 2020, 18:14 UTC
Message-ID
<87o8pe3ou6.fsf@osv.gnss.ru>
In-Reply-To
<xmqqzh8zgcfp.fsf@gitster.c.googlers.com>
Junio C Hamano <gitster@pobox.com> writes:
Show 37 quoted lines
> I have been disturbed by this for a long time, but not strongly
> enough to do anything to it.
>
> This sequence works
>
>     $ git checkout -b newbranch
>     $ git commit --allow-empty -m one
>     $ git show -s newbranch@{1}
>
> and shows the state that was immediately after the newbranch was
> created.
>
> But then if you do
>
>     $ git reflog expire --expire=now refs/heads/newbranch
>     $ git commit --allow=empty -m two
>     $ git show -s newbranch@{1}
>
> you'd be scolded with
>
>     fatal: log for 'newbranch' only has 1 entries
>
> While it is true that it has only 1 entry, we have enough
> information in that single entry that records the transition between
> the state in which the tip of the branch was pointing at commit
> 'one' to the new commit 'two' built on it, so we should be able to
> answer "what object newbranch was pointing at?".  But we refuse to
> do so.  
>
> 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.
>
> Opinions?

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.

-- Sergey
Previous: Junio C HamanoNext: Junio C Hamano
Message 2 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.