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
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.
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 asmudge
command, either of which can be left unspecified.
Uponcheckout
, when thesmudge
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, theclean
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.