I'm trying to filter some files that contain passwords so that passwords are not committed to my repository (the rest of the file must be be committed, though, and there's no way to put the passwords in their own file). I'm trying to replicate the solution given here for Windows, where you simply mark password lines with a #gitignore
at the end and the filter prevents them being saved in the repo.
I'm trying to use Windows' findstr
to filter the file. First I register the filter:
#in gitattributes
myfile.txt filter=gitignore
then I create the filters like this:
>git config --global filter.gitignore.clean "findstr /v #gitignore$"
>git config --global filter.gitignore.smudge "type"
The /v
option prints all lines except for the ones that match. I made sure that myfile.txt ends in a newline so as not to make findstr
hang. However, when I do git add myfile.txt
or git reset
after the add, I get this error:
error: external filter findstr /v #gitignore$ failed 1
error: external filter findstr /v #gitignore$ failed
The filter fails and the password lines are added to the index.
How can I fix this filter so that it works properly?