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

git stash --keep-index doesn't have the expected behaviour

From
DBDaryl Van Den Brink <daryl.vandenbrink@maptek.com.au>
Date
Feb 23, 2018, 08:15 UTC
Message-ID
<CAC4jX8GEg5=9BPepYLntGRG7n_84ju7rTSYO82SQyuiiff0UcQ@mail.gmail.com>

If you search the internet for "git stash only unstaged changes" you can find much misleading information about what "git stash --keep-index" does. However, it is my opinion that the --keep-index option is broken, in that it doesn't do what 90% of people want it to do - that is, stash only the unstaged changes and not include the staged changes in the stash. You can find many hacks to work around this limitation, none of which are very satisfactory.

It was pointed out by some commenters on Stack Overflow that the examples given in the documentation at https://git-scm.com/docs/git-stash imply that the intended behaviour of "git stash --keep-index" is to stash only the unstaged changes. Based on that, they reason that it's actually a bug. I'm not sure that's true, but I find the existing behaviour of "--keep-index" puzzling because I can't think of when I would use it (whereas stashing only unstaged changes is a feature I would frequently use).

Is it possible that --keep-index could be fixed/improved/modified to stash only the unstaged changes, or alternatively a new option introduced which does this?

-- 
Daryl van den Brink
Software Engineer
Maptek | 31 Flemington Street, Glenside, SA 5065, Australia
Tel: +61-8 8338 9222 | Dir: +61-8 8338 9222 | Fax: +61-8 8338 9229
daryl.vandenbrink@maptek.com.au | www.maptek.com
Message 1 of 1 in “git stash --keep-index doesn't have the expected behaviour”
  1. Daryl Van Den BrinkFeb 23, 2018

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.