1

In my project I have config files that have private information. I committed some example templates to Github, but I have the actual configs in my working copy so I can build from it and I don't want them available to commit.

I tried using .gitignore, but the templates are already tracked. I tried git rm filename but that tries to delete the templates. I tried git update-index --assume-unchanged filename and git update-index --skip-worktree filename but they still show up as "modified" when using git status (and under Files to Commit in Github for Windows).

Is there any way to ignore changes that I've already made without removing the templates from Github?

Chip
  • 37
  • 1
  • 6

1 Answers1

1

That looks like what a content filter driver (using .gitattributes declaration) is for:

  • the smudge part could replace the template content with the actual value (on checkout)
  • the clean part could restore the template (on commit)

enter image description here

(image from "Customizing Git - Git Attributes", from "Pro Git book")

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Will git recognize the cleaned config is unchanged or will it still be added when I do `git add .`? It makes me nervous to commit those files and trust the filter will clean them. – Chip Mar 02 '15 at 20:17
  • 1
    Actually, a git status will show them unchanged (before git add and git commit) because the clean filter is able to restore them to their original form: so no worries, add and commit won't include those files. – VonC Mar 02 '15 at 20:25
  • I do that for instance for gitolite (https://github.com/VonC/compileEverything/tree/b7c1d6c48d76859605f4a06896e0e1f797656c82/gitolite), where I replace the shebang directive (https://github.com/VonC/compileEverything/blob/b7c1d6c48d76859605f4a06896e0e1f797656c82/gitolite/shebang_replace) but where I restore the original shebang directive (https://github.com/VonC/compileEverything/blob/b7c1d6c48d76859605f4a06896e0e1f797656c82/gitolite/shebang_restore): those files never show up as modified. – VonC Mar 02 '15 at 20:26
  • I guess I'll need to use Cygwin and sed to do the filtering on Windows? – Chip Mar 02 '15 at 20:42
  • 1
    @Chip no you can use sed on Windows, without using Cygwin. I use GoW https://github.com/bmatzelle/gow/wiki. Plus don't forget those script are executed by git, in a git bash session (even on Windows), so `sed` is there (packaged with msysgit) For example: `C:\prgs\git\PortableGit-1.9.0-preview20140217\bin\sed.exe`. – VonC Mar 02 '15 at 20:46