git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Sergey Organov <sorganov@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Annoyance wrt ref@{1} and reflog expiry
Date: Fri, 19 Jun 2020 13:31:42 -0700	[thread overview]
Message-ID: <xmqqwo42g5ld.fsf@gitster.c.googlers.com> (raw)
In-Reply-To: <87o8pe3ou6.fsf@osv.gnss.ru> (Sergey Organov's message of "Fri, 19 Jun 2020 21:14:25 +0300")

Sergey Organov <sorganov@gmail.com> writes:

>> 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.

  reply	other threads:[~2020-06-19 20:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-19 18:03 Annoyance wrt ref@{1} and reflog expiry Junio C Hamano
2020-06-19 18:14 ` Sergey Organov
2020-06-19 20:31   ` Junio C Hamano [this message]
2020-06-19 20:36     ` Mike Hommey
2020-06-19 21:49       ` Junio C Hamano
2020-06-19 20:44     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqwo42g5ld.fsf@gitster.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=sorganov@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).