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

Re: stashing only unstaged changes?

From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Date
Jun 24, 2022, 15:32 UTC
Message-ID
<220624.86czeyhy8x.gmgdl@evledraar.gmail.com>
In-Reply-To
<CA+JQ7M8gaEWHHdx2or2kQfYpp=XBxQS=pXtEOS4x5SBdpPWdkQ@mail.gmail.com>
On Fri, Jun 24 2022, Erik Cervin Edin wrote:
Show 26 quoted lines
> On Fri, Jun 24, 2022 at 3:20 PM Ævar Arnfjörð Bjarmason
> <avarab@gmail.com> wrote:
>>
>> Is what you want equivalent to:
>>
>>     # save the "git add -p"'d chunks
>>     git stash push --staged
>>     # save the "uncommitted"
>>     git stash push
>>     # pop the previously staged
>>     git stash pop --index stash@{1}
>>
>> ?
>
> Never noticed --staged before.
> I just tried to
>   seq 1 3 >> bar
> then git add -p to stage with 2 and 3
> followed by a git stash push --staged but that gave me the error
>
>> error: patch failed: bar:2
>> error: bar: patch does not apply
>> Cannot remove worktree changes
>
> But I'm guessing the command (and approach) work fine if the
> staged/unstaged are in different files.
Huh!

No, it does work when you stage chunks in the same file, I tested this by modifying the top & bottom of our README.md.

But we do indeed have that error (which looks like an unrelated bug) if you try to "git stash pust --staged" a hunk when that hunk overlaps with changes that are unstaged.

Previous: Erik Cervin EdinNext: Junio C Hamano
Message 9 of 10 in “stashing only unstaged changes?”
  1. Tim ChaseJun 21, 2022
  2. RetoJun 24, 2022
  3. Tim ChaseJun 24, 2022
  4. Konstantin KhomoutovJun 24, 2022
  5. Erik Cervin EdinJun 24, 2022
  6. Tim ChaseJun 24, 2022
  7. Ævar Arnfjörð BjarmasonJun 24, 2022
  8. Erik Cervin EdinJun 24, 2022
  9. Ævar Arnfjörð BjarmasonJun 24, 2022
  10. Junio C HamanoJun 24, 2022

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.