git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [FEATURE] Proposal: git stash --only-unstaged
@ 2025-08-13  8:51 J. Dettweiler
  2025-08-13 15:30 ` Junio C Hamano
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: J. Dettweiler @ 2025-08-13  8:51 UTC (permalink / raw)
  To: git

Hi all,

I’ve run into a recurring workflow problem when splitting commits during 
an interactive rebase, and I think Git could benefit from an option to 
stash *only* the working tree (unstaged) changes, without saving or 
restoring the index (staged changes) at all.

---

**Scenario:**
- I have a commit that needs to be split.
- I stage the part of the changes that will remain in the earlier commit 
(this becomes the new, fixed commit).
- The rest of the changes (which belong in a later commit) remain 
unstaged in the working tree.
- I want to test the staged commit in isolation before actually 
committing it, without losing or committing the later changes.
- After testing, I want to bring back the unstaged changes exactly as 
they were.

---

**Current limitations:**
- `git stash --keep-index` still saves the index in the stash object.
- When I later `git stash pop`, Git tries to restore those staged 
changes, often causing merge conflicts if I’ve modified them during the 
test.
- `git stash -p` and `git diff`+`git apply` can work as workarounds, but 
they are clunky and error-prone in longer rebases.
- The goal is essentially:
   > “stash the working tree only, leave the index untouched and 
unrecorded in the stash.”

---

**Proposed feature:**
A new option, for example: git stash push --only-unstaged

---

This would:
- Save only the unstaged working tree changes to the stash.
- Leave the index both in the working directory and completely absent 
from the stash object.
- Make `stash pop` safe even if the index has changed in the meantime.

---

**Benefits:**
- Cleaner workflows for splitting commits during interactive rebases.
- Safer testing of staged changes in isolation.
- Avoids unnecessary conflicts on stash pop.

---

I have not found an existing Git command that provides this exact 
behavior, nor an option to `git stash` that prevents the index from 
being stored in the stash object.

Has this been considered before? Would there be interest in adding such 
an option?

Thanks for your time and for Git!

J. Dettweiler


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2025-09-16 17:10 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-13  8:51 [FEATURE] Proposal: git stash --only-unstaged J. Dettweiler
2025-08-13 15:30 ` Junio C Hamano
2025-08-13 17:02 ` D. Ben Knoble
2025-08-16 16:12 ` Phillip Wood
2025-08-17 16:08   ` Junio C Hamano
2025-08-18 15:14     ` Phillip Wood
2025-08-18 23:41       ` Ben Knoble
2025-08-29 13:06         ` Phillip Wood
2025-08-29 13:30           ` D. Ben Knoble
2025-09-16 11:03             ` Phillip Wood
2025-09-16 17:10               ` D. Ben Knoble

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).