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.
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
提交你的索引,创建一个修复提交,并使用autosquash重定位:
git commit
git add -p # add the change forgotten from HEAD^
git commit --fixup HEAD^ # commits with "fixup! <commit message of HEAD^>"
git rebase --autosquash -i HEAD~3
链接地址: http://www.djcxy.com/p/24506.html
上一篇: 藏到变化到特定的文件
下一篇: 你如何告诉git只存储索引?