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

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

From
Piotr Krukowiecki <piotr.krukowiecki@gmail.com>
Date
Mar 11, 2011, 18:47 UTC
Message-ID
<4D7A6E37.8080104@gmail.com>
Hi,

I wanted to do something like "Testing partial commits" described in git-stash documentation (see end of mail for reference). I think this is a common scenario: you start working on some feature, then discover a bug, start fixing it, but realize it needs more work. So now you have two features that needs more work (both are not ready for committing).

The documentation says to use --keep-index in this case.

The problem is that --keep-index leaves changes in index intact, but at the same time it saves them in stash. So if I edit those changes I'm likely to get conflicts when applying the stash.

For example:

$ git init && echo a > a && git add . && git commit -m a $ echo x > a && git add a && git stash save --keep-index $ echo y > a && git add a && git commit -m y $ git stash pop Auto-merging a CONFLICT (content): Merge conflict in a

Maybe --keep-index should not stash staged changes? This would fix this problem. And I can't think of a situation when would want to stash changes and at the same time keep them.

If --keep-index works correctly maybe a new option, for example --index-only (or --cached-only?) could be introduced?

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Testing partial commits::

You can use `git stash save --keep-index` when you want to make two or more commits out of the changes in the work tree, and you want to test each change before committing: + ---------------------------------------------------------------- # ... hack hack hack ... $ git add --patch foo # add just first part to the index $ git stash save --keep-index # save all other changes to the stash $ edit/build/test first part $ git commit -m 'First part' # commit fully tested change $ git stash pop # prepare to work on all other changes # ... repeat above five steps until one commit remains ... $ edit/build/test remaining parts $ git commit foo -m 'Remaining parts' ----------------------------------------------------------------

-- 
Piotr Krukowiecki
Next: Neal Kreitzinger
Message 1 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.