14

"Cannot rewrite branch(es) with a dirty working directory".

I am new to Git - I tried googling for an answer to no avail.

What does this error mean? What should/can I do?

jldupont
  • 93,734
  • 56
  • 203
  • 318
  • it is my first git repo and I had committed something not belonging... had to correct it. – jldupont Jan 08 '10 at 20:52
  • I'm having the same problem and I'm experienced with git. If I do `git filter-branch --subdirectory-filter somedir -- --all` I end up with my whole repo processed but if I do `git filter-branch --tree-filter `rm somefile` -- --all` it quits after processing the first branch with the error mentioned above. Why does `filter-branch` save the state of `--subdirectory-filter` but stop if `--tree-filter` changes the directory? – Chris Nelson Oct 12 '11 at 19:24

1 Answers1

24

A dirty working directory means you have uncommitted changes to your branch. You can either commit them or stash them. To stash just use:

git stash

And use this to bring your changes back

git stash apply
jonescb
  • 22,013
  • 7
  • 46
  • 42
  • 3
    Note that you might actually not have a dirty working directory: there's a bug in git prior to 1.7.7.1 which means git doesn't refresh its internal indexes when running `filter-branch`. So try running these two commands anyway - unless anyone knows of a less hacky way to force index refresh. (More discussion of this on [this question](http://stackoverflow.com/questions/6463963/git-filter-branch-says-working-tree-is-dirty-when-it-is-not) .) – J-P May 16 '12 at 11:04
  • 2
    From a comment added at the link above: `git update-index -q --ignore-submodules --refresh` should update the index! – J-P May 16 '12 at 15:17
  • You can use `git stash pop` to apply the last stashed changes and remove them from the stash list. `apply` will apply the changes but a `git stash list` still shows the stashed changes. – Vangelis Tasoulas Mar 30 '17 at 17:11