Removing sensitive data from Git. “fatal: ambiguous argument 'rm'”

蓝咒 提交于 2019-11-30 17:46: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 GIT_COMMITTER_EMAIL=just.a.test@kernel.org GIT_AUTHOR_EMAIL=just.a.test@kernel.org; git commit-tree \"$@\"" HEAD

Multiple lines:

git filter-branch --commit-filter "GIT_COMMITTER_NAME=void \
                                   GIT_AUTHOR_NAME=void \
                                   GIT_COMMITTER_EMAIL=just.a.test@kernel.org \
                                   GIT_AUTHOR_EMAIL=just.a.test@kernel.org; \
                                   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!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!