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

Re: git gc destroys autostash

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 7, 2024, 21:05 UTC
Message-ID
<xmqq7cjg6l3r.fsf@gitster.g>
In-Reply-To
<CAGHpTBKpYp370QTw93wK_RP+X2S+44jd-8kjodiUj4k0BoAEqA@mail.gmail.com>
Orgad Shaneh <orgads@gmail.com> writes:
Show 13 quoted lines
> 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.

Show 7 quoted lines
> git rebase --continue
> # fatal: '3b88163a1bff3859a005554c168d94e5357ee45b' is not a stash-like commit
> # error: cannot store 3b88163a1bff3859a005554c168d94e5357ee45b
> # Successfully rebased and updated refs/heads/master.
>
> Thanks,
> - Orgad
Previous: Orgad ShanehNext: Kristoffer Haugsbakk
Message 2 of 3 in “git gc destroys autostash”
  1. Orgad ShanehFeb 7, 2024
  2. Junio C HamanoFeb 7, 2024
  3. Kristoffer HaugsbakkFeb 7, 2024

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.