Git stash: “Cannot apply to a dirty working tree, please stage your changes”

后端 未结 11 1653
青春惊慌失措
青春惊慌失措 2020-12-12 09:04

I am trying to apply changes I stashed earlier with git stash pop and get the message:

Cannot apply to a dirty working tree, please stage your c         


        
11条回答
  •  -上瘾入骨i
    2020-12-12 09:21

    You can do this without having to stash your current changes by exporting the stash you want as a patch file and manually applying it.

    For example, say you want to apply stash@{0} to a dirty tree:

    1. Export stash@{0} as a patch:

      git stash show -p stash@{0} > Stash0.patch

    2. Manually apply the changes:

      git apply Stash0.patch

    If the second step fails, you will have to edit the Stash0.patch file to fix any errors and then try git apply again.

提交回复
热议问题