Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
894 views
in Technique[技术] by (71.8m points)

linux - Removing sensitive data from Git. "fatal: ambiguous argument 'rm'"

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>...]'
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...