21

I'm trying to run this command:

git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch filename.js' --prune-empty --tag-name-filter cat -- --all

but I keep getting this error:

fatal: ambiguous argument 'rm': unknown revision or path not in the working tree
.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
3
  • This might be better addressed at the Server Fault site Commented Jan 28, 2014 at 0:26
  • 6
    From Windows CMD, use doble quotes " instead of single ' Commented Apr 5, 2017 at 15:20
  • Executing from Git Bash worked for me
    – sillo01
    Commented Aug 12, 2020 at 16:54

2 Answers 2

28

It depends on the shell you are using.
On Windows, with msysgit for instance, see issue 477:

Single quotes do not have a special meaning with CMD. Do not expect that they work the same as with a POSIX shell. Call filter-branch like this:

git filter-branch --commit-filter "GIT_COMMITTER_NAME=void GIT_AUTHOR_NAME=void [email protected] [email protected]; git commit-tree \"$@\"" HEAD

Multiple lines:

git filter-branch --commit-filter "GIT_COMMITTER_NAME=void \
                                   GIT_AUTHOR_NAME=void \
                                   [email protected] \
                                   [email protected]; \
                                   git commit-tree \"$@\"" HEAD

As mentioned in "How to pass a programmatically generated list of files to git filter-branch?"

Each argument to the various ...-filters needs to be a single string. That string is saved as a shell variable.

So make sure 'git rm --cached --ignore-unmatch filename.js' is considered a string in the shell you are in.
As Constantine Ketskalo points out in the comments:

Windows 10, PyCharm, GitPython, same command as in question.
Simply changed ' to " inside the string and it worked!

4
  • I tried doing this call twice (using the corrected format), only to get on the second time the following: Cannot create a new backup. A previous backup already exists in refs/original/ Force overwriting the backup with -f rm: cannot remove '/YOURPATH/.git-rewrite/backup-refs': Permission denied rm: cannot remove directory '/YOURPATH/.git-rewrite': Directory not empty.
    – drzaus
    Commented Oct 3, 2014 at 14:05
  • @drzaus yes, you might have to remove manually the /YOURPATH/.git-rewrite folder.
    – VonC
    Commented Oct 3, 2014 at 14:38
  • So make sure 'git rm --cached --ignore-unmatch filename.js' is considered a string in the shell you are in. VonC, thank you so much. It saved me who knows how much more time it could be. Windows 10, PyCharm, GitPython, same command as in question. Simply changed ' to " inside the string and it worked! Commented May 30, 2019 at 12:47
  • 1
    @ConstantineKetskalo Thank you for this feedback. I have included your comment in the answer for more visibility.
    – VonC
    Commented May 30, 2019 at 22:55
2

On windows, you have to use double quote " instead of single '

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.