简体   繁体   English

GitHub:如何在存储库中维护文件的两个不同版本?

[英]GitHub: how to maintain two different versions of files different in repositories?

Should I use .gitignore for this? 我应该为此使用.gitignore吗?

I want to maintain an .htaccess file in my local repository which is also the root directory of apache. 我想在本地存储库中维护一个.htaccess文件,该文件也是apache的根目录。 The .htaccess file is different from what I have in a remote repository which also serves as my production server. .htaccess文件不同于我在用作我的生产服务器的远程存储库中的文件。

What should I do so that I have a "generic" .htaccess in the github repository while all other repositories may maintain their own copies which will not be uploaded to any of the remote repositories? 我应该怎么做才能在github存储库中拥有一个“通用” .htaccess ,而所有其他存储库都可以维护自己的副本,而这些副本不会上传到任何远程存储库中? I want the file to be retained locally only. 我希望仅在本地保留文件。

This is also the same case for configuration files, for instance, config.php contains database username/host/password/name which may be different among the repositories. 配置文件也是如此,例如config.php包含数据库用户名/主机/密码/名称,这在存储库中可能有所不同。

Thanks! 谢谢!

Instead of ignoring the files, you could create a "branch" just for the production server, always merging the "master" changes inside that new branch before every deploy. 除了忽略文件之外,您还可以为生产服务器创建一个“分支”,始终在每次部署之前将“主”更改合并到该新分支中。 In the production branch, you can commit configuration changes that apply only to the production environment. 在生产分支中,您可以提交仅适用于生产环境的配置更改。

This same strategy applies to any number of environments. 相同的策略适用于任何数量的环境。

Remember: never merge the "production" branch back to "master", otherwise you'll end up with a lot of problems with the config files. 切记:切勿将“生产”分支合并回“主”分支,否则最终将导致配置文件出现许多问题。 If you need to fix something on production, use a "bugfix" branch, starting on the most recent master commit that is merged into production, merging it back to production AND master after the work is done. 如果您需要在生产中修复某些问题,请使用“ bugfix”分支,该分支从合并到生产中的最新主提交开始,在工作完成后将其合并回生产和主。

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

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