Re: stashing only unstaged changes?
- From
- Konstantin Khomoutov <kostix@bswap.ru>
- Date
- Jun 24, 2022, 09:55 UTC
- Message-ID
- <20220624095558.hegsfj4e4nbqyooo@carbon>
- In-Reply-To
- <20220621142618.239b02cd@bigbox.attlocal.net>
On Tue, Jun 21, 2022 at 02:26:18PM -0500, Tim Chase wrote:
Show 5 quoted lines
> 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*.
I tend to rely on reflogs for this. Basically, I roll like this:
1. Stage the necessary changes, commit.
2. Stage the remaining changes - what you've left unstaged in your case, -
commit.
3. Go to the commit I need to test; in this simple case that'd be$ git checkout HEAD~
Then test the changes.
4. Go back to the previous state using the HEAD's reflog:
$ git checkout HEAD@{1}If you now need to have the situation where the changes committed on step 2 are left only in the work tree, run
$ git reset HEAD~
so that you have the HEAD and the index reset to the commit recorded on step 1 with the changes from the commit 2 left in the work tree.
Having said that, I'd note that I tend to do work on the detached HEAD but you could apply the same logic to working on a a branch.