From: Tim Chase <git@tim.thechases.com>
To: git@vger.kernel.org
Subject: stashing only unstaged changes?
Date: Tue, 21 Jun 2022 14:26:18 -0500 [thread overview]
Message-ID: <20220621142618.239b02cd@bigbox.attlocal.net> (raw)
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)
next reply other threads:[~2022-06-21 19:46 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-21 19:26 Tim Chase [this message]
2022-06-24 8:16 ` stashing only unstaged changes? 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220621142618.239b02cd@bigbox.attlocal.net \
--to=git@tim.thechases.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.