简体   繁体   English

使用git repo处理.htaccess的最佳方法是什么?

[英]What is the best way to handle .htaccess with a git repo?

Another developer says we should put .htaccess files in the git repo, but because the live server uses passwords and our local boxes don't, I said we should put them in the .gitignore. 另一位开发人员说我们应该把.htaccess文件放在git repo中,但由于实时服务器使用的是密码而本地的盒子没有,我说我们应该把它们放在.gitignore中。 However, he says that if you have to have different .htaccess files across instances, you're doing it wrong. 但是,他说,如果你必须跨实例使用不同的.htaccess文件,那你就错了。 I argue not all server instances are going to be the same, and sometimes (if not often) they require their own configurations. 我认为并非所有服务器实例都是相同的,有时(如果不经常)它们需要自己的配置。 He agreed that we could simply create a "htaccess" file in repo that is copied to .htaccess on live, but still preferred doing it his way. 他同意我们可以简单地在repo中创建一个“htaccess”文件,该文件在现场复制到.htaccess,但仍然喜欢按照他的方式进行操作。 To me, things like server config should be kept out of repo. 对我来说,服务器配置之类的东西应该不受回购。 Also I'm not sure I need to change my development OS just to match a live server exactly or run VM software. 此外,我不确定是否需要更改我的开发操作系统,以便与实时服务器完全匹配或运行VM软件。 Am I missing something here? 我在这里错过了什么吗? Which is the best way, or what's a better alternative? 哪种方式最好,或者哪种方式更好?

I think of git as mainly a tracker for software components (such as lines of code) and not software configuration. 我认为git主要是软件组件(如代码行)的跟踪器,而不是软件配置。

A server password is configuration and therefore to be excluded from change control. 服务器密码是配置,因此要从更改控制中排除。 The .htaccess file is a configuration artefact necessary (As I understand it in your case) for the correct operation of your application, and therefore subject to change control via git. .htaccess文件是一个必要的配置工具(正如我在你的例子中所理解的),用于正确操作你的应用程序,因此需要通过git进行更改控制。

The way I see it you have two options. 我看到它的方式你有两个选择。 It strikes me as more elegant to move the configuration out of the repo, but if you have to keep it in the .htaccess file you can use smudge/clean scripts in .gitattributes . 将配置移出repo更加优雅,但是如果你必须将它保存在.htaccess文件中,你可以在.gitattributes中使用smudge / clean脚本 Smudge/clean filters inject defined changes into tracked content upon checkout (ie injecting passwords) and clean the password out of the tracked content again upon staging (ie substitute the password with a generic foobar). 涂抹/清洁过滤器在结账时将定义的更改注入跟踪的内容(即注入密码),并在分段时再次从被跟踪的内容中清除密码(即用一般的foobar替换密码)。

Bear in mind, since these smudge/clean filters are defined in the git config they do not get passed around the way otherwise tracked files do, so you need to keep track yourself that the right filters are in place where they should be. 请记住,因为这些涂抹/清洁过滤器是在git配置中定义的,所以它们不会被跟踪文件所传递,所以你需要自己跟踪正确的过滤器应该放在哪里。

In either case, whether you keep the configuration out of the repo or do manual smudge/filter management across instances of the repo, you'd benefit from having a use protocol for git which would (amongst other things) state how you handle configuration and state rules for which smudge/clean scripts go where and/or where server configuration lives. 在任何一种情况下,无论您是将配置保留在repo之外,还是在repo的实例之间进行手动涂抹/过滤管理,您都可以从git的使用协议中受益,该协议将(除其他事项外)说明您如何处理配置和涂抹/清理脚本进入服务器配置所在的位置和/或位置的状态规则。

Since the .htaccess seems to be specific for the environment and not an essential part to make the application run, i would not add it to the repo. 由于.htaccess似乎特定于环境而不是使应用程序运行的必要部分,因此我不会将其添加到repo中。

maybe the nicest solution would be to not use .htaccess on these servers where you need the authentication, but just enable the authentication in the serverconfig. 也许最好的解决方案是在需要身份验证的服务器上不使用.htaccess,而只是在serverconfig中启用身份验证。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM