stashing only unstaged changes?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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)



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux