Can I interactively pick hunks from another git commit?

后端 未结 4 929
梦谈多话
梦谈多话 2021-02-01 16:50

I\'m looking for exactly the same behavior as

git add -i -p

But instead of composing a commit from my working directory, I\'d like to compose

4条回答
  •  离开以前
    2021-02-01 17:34

    You could use git reset --mixed HEAD^1 to revert the index, then pick the hunks you want with git add -i.

    The reset will roll back the index to the previous commit (essentially un-committing whatever was the HEAD), but it won't touch the working tree. You can now stage the hunks you want, commit them and throw away the rest with a git reset --hard HEAD.

提交回复
热议问题