10

I'm trying to rewrite my history in my git repository because I need to remove a file that contains restricted information.

This is what happens:

$ git filter-branch --index-filter 'git rm --cached --ignore-unmatch FILE' master Cannot rewrite branch(es) with a dirty working directory. 

So I think "that's weird, I'm pretty sure I don't have uncommitted changes", and I run:

$ git status -u # On branch master nothing to commit (use -u to show untracked files) 

What is going on here? Does anyone have an idea for what could be happening? There are submodules in this repository.

Submodule Staging Info

I have 18 submodules (all Vim plugins), and here are their statuses. Thought this might be useful info.

$ for i in $(ls); do cd $i; git status -u; cd ..; done; # Not currently on any branch. nothing to commit (working directory clean) # Not currently on any branch. nothing to commit (working directory clean) # Not currently on any branch. nothing to commit (working directory clean) # Not currently on any branch. nothing to commit (working directory clean) # Not currently on any branch. nothing to commit (working directory clean) # Not currently on any branch. nothing to commit (working directory clean) # Not currently on any branch. nothing to commit (working directory clean) # Not currently on any branch. nothing to commit (working directory clean) # Not currently on any branch. nothing to commit (working directory clean) # Not currently on any branch. nothing to commit (working directory clean) # Not currently on any branch. nothing to commit (working directory clean) # On branch master nothing to commit (working directory clean) # Not currently on any branch. nothing to commit (working directory clean) # Not currently on any branch. nothing to commit (working directory clean) # Not currently on any branch. nothing to commit (working directory clean) # Not currently on any branch. nothing to commit (working directory clean) # Not currently on any branch. nothing to commit (working directory clean) # Not currently on any branch. nothing to commit (working directory clean) 

Other info

$ git diff-files --ignore-submodules --quiet $ echo $? 1 $ git diff-index --cached --quiet HEAD -- $ echo $? 0 
11
  • did you try filter-branch again after running git status? Maybe only the timestamp of a file changed and filter-branch doesn't check for that to remove the dirty flag Commented Jun 24, 2011 at 5:58
  • Yep, I did. Same result. Commented Jun 24, 2011 at 6:04
  • then it's most likely due to the submodules, with which I don't have any experience, sorry Commented Jun 24, 2011 at 6:06
  • 1
    What does git status -u show? Also have you tried removing any untracked files and or doing this on a completely new clone? Commented Jun 24, 2011 at 6:33
  • 3
    The command you pasted does not give the submodule status, but the same supermodule status several times. Please check the exit status of the following commands: "git diff-files --ignore-submodules --quiet", "git diff-index --cached --quiet HEAD --" Commented Jun 24, 2011 at 7:49

1 Answer 1

7

This is mostly a guess, but the error may be caused by a bug that was fixed in git v1.7.7.1 (which was released after your original post). From the commit message:

Filter-branch already requires that we have a clean work tree before starting. However, it failed to refresh the index before checking, which means it could be wrong in the case of stat-dirtiness.

Sign up to request clarification or add additional context in comments.

4 Comments

Prior to 1.7.7.1 (I have 1.7.0.4) you'll presumably need to force git to refresh the index. I've found that you can do this by running git stash and then git stash apply, as if you did have a dirty working dir (taken from this question ). Git will complain, but filter-branch should then work. If anyone has a less hacky method then please mention it here!
@J-P: The fix linked in my answer causes git filter-branch to run the following to refresh the index: git update-index -q --ignore-submodules --refresh
Switching from 1.7.1 to 1.8.3.4 fixed this issue for me.
I had this issue when trying to split a directory into a separate repo via

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.