views:

135

answers:

2

Hello,

I would like a specific string in a specific file to be hidden every time I commit changes to that file.

Actually, I have a URL in a file that shouldn't be public in a remote repository. Is there anyway to hide it using pre-commit and post-commit hooks or something similar?

Currently I am working with a git repository but it would be nice to know how to do this with svn.

Thanks, Simão

+4  A: 

You could keep that string in a separate file (such as a resource file, if your environment supports that), and not put that file under version control.

Sparr
I would do this as well. It's cleaner both in terms of not having to use git hooks and in having a central place to store sensitive information.
Jimmy Cuadra
+1. That would be the easiest way, both for the source control system, and for maintaining installation-specific settings. But at least with git, there should be a way to make the original plan work, because git (unlike svn) allows partial file commits.
Thilo
Yes, actually a simple solution like this would work. Thanks :)
simao
+2  A: 

If you really must have that file under version control, use a git attribute filter driver (see also GitPro book).

A filter driver consists of a clean command and a smudge command, either of which can be left unspecified.
Upon checkout, when the smudge command is specified, the command is fed the blob object from its standard input, and its standard output is used to update the worktree file.
Similarly, the clean command is used to convert the contents of worktree file upon check-in.

That way, the script (a private version, only in your repo, not managed by Git) referenced by the smudge can replace the coded URL, while the clean script will restore its content to a coded URL.
A public version of the same script, managed by git and pushed everywhere would do... nothing and keep the URL obfuscated.

alt text

VonC
Thanks. That's what I was looking for.
simao