git/list[1] front-page[2] threads[3] people[4] search[5] about
wed 2026-10-07 18:03 UTC

Re: [PATCH v2] push: fix --force-if-includes when remote-tracking ref has no reflog

From
Tyler Cipriani <tyler@tylercipriani.com>
Date
Sep 25, 2026, 20:53 UTC
Message-ID
<arbfQ7xF1NgDeilU@localhost.localdomain>
In-Reply-To
<xmqqv78dordu.fsf@gitster.g>
On 26-09-09 17:57:01, Junio C Hamano wrote:
<snip>
>Doesn't that mean it is more logical to use the default gc
>expiration timeout than year 1970 and in any cases using the usual
>gc expiration would not waste more time than using 1970, right?
I like date=0 (i.e., 1970).

Tested locally, in _most_ cases both give the right answer. But date=<cutoff> can give the wrong answer in a subset of cases, and date=0 can give a slower answer in a subset of cases.

I think the wrong answer is worse, and I think the case where date=<cutoff> provides a wrong answer is common for me (with default gc settings and lots of old git clones).

The important bits of is_reachable_in_reflog:
- date: initial: either gc.reflogExpire (default: 90 days) or 0. Later:
   maybe set by a walk of remote reflog.
- remote: e.g., remotes/origin/<x>
- local: e.g., refs/heads/<x>
- remote->old_oid: advertised oid for remote ref

We need to find remote->old_oid in the local reflog. We can't build on a commit we've never fetched, so we set date to the last time remote's reflog moved to bound our walk of local.

But remote's reflog can expire or be empty, so it needs an initial value.

With date=0 (and remote gone: older than 90 days + gc, removed, or fresh clone), we walk local until we find the remote->old_oid or we run out of reflog to walk. But local is also subject to gc, so by default that's 90 days without having to bound anything. Since both reflogs are gc'd, the time difference should be minimal.

With date=<cutoff> is only faster where we have no remote reflog, we don't have remote->old_oid in our local, and our local reflog has entries older than the typical gc cutoff; viz. I'm rebuilding history without the remote tip and: (a) expired my remote reflog manually (b) have my remote reflog gc configured differently than my local or (c) I have gc turned off.

But in one case, date=0 gives the right answer and the cutoff date gives the wrong answer:

     git clone ...            # 1. files backend, no remote reflog
     git reset --hard HEAD^   # 2. start a rewrite
     ...                      # 3. do nothing for gc.reflogExpire amount
     ...                      #    of time.
     ...                      #    Remote never moves/we never fetch.
     git commit ...           # 4. Finish rewrite and push
     git push --force-if-includes --force-with-lease origin main

Push fails with date=gc.reflogExpire (wrong). Push succeeds with date=0 (right).

And nothing about gc config need be tweaked from the defaults for this to happen---git gc can even happen (provided it runs between the initial clone and the reset, since the reflogUnreachable prune is 30 days by default). But in small repos, gc may not have been triggered at all.

So date=0 is always correct and should have equivalent in runtime in most cases. And it neatly side-steps what cut off should we use? gc.reflogExpire vs. gc.<remote>.reflogExpire vs. gc.<local>.reflogExpire vs. flat 90 days vs. do we respect gc.reflogExpire=never.

Thanks.
Previous: Aleksei SviridkinNext: Junio C Hamano
Message 22 of 27 in “push: fix --force-if-includes when remote-tracking ref has no reflog”
  1. push: fix --force-if-includes when remote-tracking ref has no reflogAleksei Sviridkin, Sep 3, 2026
  2. Junio C HamanoSep 3, 2026
  3. Aleksei SviridkinSep 3, 2026
  4. Junio C HamanoSep 3, 2026
  5. Aleksei SviridkinSep 3, 2026
  6. Kristoffer HaugsbakkSep 4, 2026
  7. push: fix --force-if-includes when remote-tracking ref has no reflogAleksei Sviridkin, Sep 4, 2026
  8. Junio C HamanoSep 4, 2026
  9. Junio C HamanoSep 4, 2026
  10. push: fix --force-if-includes when remote-tracking ref has no reflogAleksei Sviridkin, Sep 5, 2026
  11. Aleksei SviridkinSep 5, 2026
  12. Junio C HamanoSep 6, 2026
  13. Kristoffer HaugsbakkSep 6, 2026
  14. Aleksei SviridkinSep 6, 2026
  15. Junio C HamanoSep 6, 2026
  16. Thomas BachemSep 7, 2026
  17. Weijie YuanSep 7, 2026
  18. Junio C HamanoSep 8, 2026
  19. Aleksei SviridkinSep 9, 2026
  20. Junio C HamanoSep 10, 2026
  21. Aleksei SviridkinSep 10, 2026
  22. Tyler CiprianiSep 25, 2026
  23. Junio C HamanoSep 25, 2026
  24. Tyler CiprianiSep 29, 2026
  25. push: fix --force-if-includes when remote-tracking ref has no reflogAleksei Sviridkin, Sep 29, 2026
  26. Junio C HamanoSep 29, 2026
  27. Junio C HamanoSep 29, 2026

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.