Alex Rivera | Logout

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

Asked 2009-09-01T05:47:56.190
141

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 changes

Any suggestion on how to deal with that?

Edit
Report

1 Answer

9

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.

answered 2010-03-30T22:44:18.563

Your Answer