I have my website/cms tracked in git and it works rather well, except for my .htaccess file. The file needs to be substantially different depending which server I am running the code on (local/test/live). As a result, right now I've kept .htaccess out of git entirely (it's in my .gitignore file). But occasionally it gets lost, and at any event it is a part of the site and I'd like it to remain tracked, but I don't want it pushed to remote repositories where it might overwrite the correct configurations for the other servers. Is there any way to make git keep a file tracked, but only locally? (Or any other way to solve the problem?)
preguntado el 09 de enero de 11 a las 07:01
Puedes hacer esto con Git's pago escaso característica. Ejecute los siguientes comandos en un repositorio donde desee un especial, sin seguimiento
git config core.sparsecheckout true echo '*' >.git/info/sparse-checkout echo '!.htaccess' >>.git/info/sparse-checkout git read-tree --reset -u HEAD
Esto primero borrar la existencia
.htaccess expediente. Pero ahora se ignora desde la perspectiva de Git, por lo que puedes poner una máquina específica allí y Git no te molestará por eso.
You can then add and manage a
.htaccess archivo de algunos otros repository (say your local one). Git will be happy to track this file and keep it in the repository, but on a machine with the above sparse checkout configuration, Git will pasar por alto El local
.htaccess archivo en ese directorio de trabajo, incluso si es diferente de lo que hay en el repositorio.
It sounds like the content of your .htaccess files are deployment-specific, and thus aren't really part of the code. In other words, these files can be generated by a deployment script to fit each server, rather than being kept in git and then having to override changes every time one of them is committed.
.htaccess in a totally separate git repository, and symlink it in the directory that your code is in. (And keep it
.gitignore'd in the original repository.)
You could have multiple branches, one for each server, so that each branch has its own version of the server specific configuration files. Then when you make a change in the master branch, those other branches would merge with it and get the latest changes - but they would keep their own configuration. If the configuration files are changed, then a manual merge would be needed, but otherwise this is something that could be automated with scripts and maybe even githooks.
If it's a security issue, the answer is going to be "no", because if git tracks the history of the file, everyone who clones that repository is going to get the full history. But if you have control over all the locations and just want a way to track it, but at those other locations to avoid checking it out, perhaps git smudge and git clean filters might do something for you. They allow you to edit the content of a file when you check it out and commit it. I'm not certain that's a good fit, but I'm trying to come up with a workable solution.
Alternatively, track the file with an alternative name (i.e., not ".htaccess"), and where applicable, and only where applicable, create a symbolic link called .htaccess to the tracked name.