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

Re: git stash: add --index-only, or --keep-index should not stash index?

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 16, 2011, 22:36 UTC
Message-ID
<7vsjum66co.fsf@alter.siamese.dyndns.org>
In-Reply-To
<AANLkTing5ZQKF4PXtX1peynx2uuc8s+aeBP=fbJWXvWw@mail.gmail.com>
Piotr Krukowiecki <piotr.krukowiecki@gmail.com> writes:
Show 17 quoted lines
> How about following workflow?
>
>    # ... hack hack hack ...
>    $ git add --patch foo
>    $ git stash save --keep-index
>    $ build/test first part         # note I have removed the "edit" part
>
> There are two possibilities now:
>
> 1. You're happy with the result - you commit your changes:
>
>    $ git commit -m 'First part'
>    $ git stash pop
>
> Important: there will be no conflicts in this case, and committed
> changes won't be reverted/applied/conflicted, because you have
> not edited them!

Exactly; I won't take _any_ credit for --keep-index (I wasn't involved deeply in "git stash"), but the above matches my understanding of its primary intended use case. For this to work well, the stash should record the index that is going to be committed and the work tree you had before stashing.

Show 13 quoted lines
> 2. You're not happy with the result - maybe something does not
> build and you need to stage more changes, or maybe fix is not
> working yet.
>
> You should first pop your stashed changes! This way you'll avoid
> conflicts, you'll be able to stage/modify other changes. So the
> next steps are like this:
>
>    $ git stash pop
>    $ edit/add -p
>    $ git stash save --keep-index
>
> and now you're back to the "build/test" part.
Yes.
Previous: Piotr KrukowieckiNext: Neal Kreitzinger
Message 6 of 7 in “git stash: add --index-only, or --keep-index should not stash index?”
  1. Piotr KrukowieckiMar 11, 2011
  2. Neal KreitzingerMar 14, 2011
  3. Piotr KrukowieckiMar 15, 2011
  4. Neal KreitzingerMar 16, 2011
  5. Piotr KrukowieckiMar 16, 2011
  6. Junio C HamanoMar 16, 2011
  7. Neal KreitzingerMar 16, 2011

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.