git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* stashing only unstaged changes?
@ 2022-06-21 19:26 Tim Chase
  2022-06-24  8:16 ` Reto
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Tim Chase @ 2022-06-21 19:26 UTC (permalink / raw)
  To: git

I recently had composed a commit with some `git add -p` leaving some
portions unstaged. I wanted to stash the unstaged changes to make
sure that the staged code ran as expected, so I did  a `git stash`
only to find that it unstaged my staged changes and stashed
*everything*.

Using `git stash --saved` does the opposite of what I want (stashing
the index, not the difference between the index and the working-copy)

So I carefully re-`git add -p`'ed everything and tried `git stash
--keep-index` which sounded promising (my index remained the same),
but popping my stash ended up causing conflicts because it had
stashed the diff of HEAD..working-copy, not INDEX..working-copy.  A
`git stash show -p` confirmed that the stash included things that I
had already staged.

So I carefully re-`git add -p`ed everything yet again, but then got
stuck trying to convince `stash` to save a snapshot of only the diff
in my working directory. To work around it, I did a `git diff >
temp.patch` to obtain the stuff I'd wanted to stash, a `git reset
--staged` to clear out those changes, ran my code to verify
(eventually committing it), and then applied the `temp.patch` back on
top of my changes.  It worked, but felt convoluted.

I did see the `git stash -p` option, to manually choose the inverse
bits, but for what I was doing, it was more sensible to `git add -p`
and try to stash the rest.

So is there some option I've missed to tell `git stash` to stash only
the delta between the uncommitted-index and the working-copy?

Thanks,

-Tim


(I'd posted this on /r/git

https://www.reddit.com/r/git/comments/vchu83/stashing_only_unstaged_changes/

but figured I'd try my hand here in the hope of more answers)

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

end of thread, other threads:[~2022-06-24 21:17 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-21 19:26 stashing only unstaged changes? Tim Chase
2022-06-24  8:16 ` Reto
2022-06-24 20:53   ` Tim Chase
2022-06-24  9:55 ` Konstantin Khomoutov
2022-06-24 11:23 ` Erik Cervin Edin
2022-06-24 20:38   ` Tim Chase
2022-06-24 13:09 ` Ævar Arnfjörð Bjarmason
2022-06-24 13:49   ` Erik Cervin Edin
2022-06-24 15:32     ` Ævar Arnfjörð Bjarmason
2022-06-24 19:47       ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).