1

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?

Community
  • 1
  • 1
Nate Glenn
  • 6,455
  • 8
  • 52
  • 95

1 Answers1

0

It would be easier to try and use unix command for your filter (which is run as a bash script by default).

  • grep (packaged with git, or, if it is too old, through Gnu On Windows)

    grep -v #gitignore$
    
  • cat (instead of type)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Mine didn't come with grep, so this fails in the exactly the same way. – Nate Glenn Jul 13 '14 at 14:51
  • @NateGlenn any msysgit release has grep. What git do you have? But Gnu On Windows can help too. – VonC Jul 13 '14 at 14:51
  • I installed it with Chocolatey. Actually `git --version` tells me it's msysgit, so I don't know why I don't have git. I know I could install more stuff with Chocolatey, but I'm trying to get a solution that doesn't require yet more software. – Nate Glenn Jul 13 '14 at 16:49
  • @NateGlenn no need for chocolate: just unzip the msysgit archive (https://github.com/msysgit/msysgit/releases/). – VonC Jul 13 '14 at 16:51