Malvineous Malvineous - 11 days ago 5x
Git Question

How do you tell git to stash the index only?

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!


Simplest way is to leave off that change right now, make your new commit, then create a second commit with just that change you want to use to amend and then use git rebase -i to squash it with the original HEAD.

An alternative would be to make your commit, tag it, roll back with git reset HEAD^, add that one change and amend HEAD, then cherry-pick your tagged commit.