I have just used "git add -p" to add a bunch of changes to the index, and I just realised that I missed a change that should've gone into the previous commit.
I can't commit --amend now because I've added all these new changes to the index, and I don't want to use 'git reset' to remove them all from the index as it will take ages to add them all back in again.
What I need is something like 'git stash' that will only stash the index - it should leave the working files alone. Then I can stash the index, add the missing change, commit it, then pop the stash and have my index back the way it was.
It doesn't look like 'git stash' is able to do this, but am I missing something? Thanks!
To stash a specific file, use the “git stash push” command and specify the file you want to stash. However, the other tracked files that may be modified in your current working directory are untouched.
To pop a specific stash in git, you can use the git stash apply command followed by the stash@{NUMBER} command. command. It will show the list of stashes you have saved.
Stage all your files that you need to stash. Run git stash --keep-index . This command will create a stash with ALL of your changes (staged and unstaged), but will leave the staged changes in your working directory (still in state staged). Now your "good stash" has ONLY staged files.
The closest thing I've found is git stash --patch
. It walks you through each of the changes to working tree and index letting you choose what to stash.
http://www.kernel.org/pub/software/scm/git/docs/git-stash.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With