public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Orgad Shaneh <orgads@gmail.com>
Cc: git <git@vger.kernel.org>
Subject: Re: git gc destroys autostash
Date: Wed, 07 Feb 2024 13:05:44 -0800	[thread overview]
Message-ID: <xmqq7cjg6l3r.fsf@gitster.g> (raw)
In-Reply-To: <CAGHpTBKpYp370QTw93wK_RP+X2S+44jd-8kjodiUj4k0BoAEqA@mail.gmail.com> (Orgad Shaneh's message of "Wed, 7 Feb 2024 22:52:00 +0200")

Orgad Shaneh <orgads@gmail.com> writes:

> Running git gc --prune=now during rebase with autostash deletes the
> autostash object, and it cannot be recovered when the rebase ends.
>
> Example:
>
> #!/bin/sh
>
> git init
> echo 1 > foo; git add foo; git commit -m 'Initial commit'
> echo 2 > foo; git add foo; git commit -m 'Second commit'
> echo 3 > foo; git rebase -i --autostash HEAD^
> # Choose edit
> git gc --prune=now

This is totally expected, unfortunately, as the autostash does not
use the ref API to use the refs/stash (presumably in order to avoid
shifting the shash@{$N} numbers). Because of that, the stash entry
is not protected from the garbage collection.  This currently falls
into "it hurts when I twist my arm this way. --do not do it then"
category.

It may be a simple fix to teach sequencer.c:apply_save_autostash()
not to use a random on-disk file to store the returned value from
"git stash create", but use a dedicated ref that is not refs/stash
for its own use via proper use of the ref API.

> git rebase --continue
> # fatal: '3b88163a1bff3859a005554c168d94e5357ee45b' is not a stash-like commit
> # error: cannot store 3b88163a1bff3859a005554c168d94e5357ee45b
> # Successfully rebased and updated refs/heads/master.
>
> Thanks,
> - Orgad

  reply	other threads:[~2024-02-07 21:05 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-07 20:52 git gc destroys autostash Orgad Shaneh
2024-02-07 21:05 ` Junio C Hamano [this message]
2024-02-07 21:47 ` Kristoffer Haugsbakk

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=xmqq7cjg6l3r.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=orgads@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