Re: stashing only unstaged changes?

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

 



On Tue, Jun 21, 2022 at 02:26:18PM -0500, Tim Chase wrote:

> 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.




[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