用于开发和实时网站的 Git
我将 Git 用于我的开发网站和实时网站,并将每个网站保留在自己的分支“dev”和“master”中。当我完成“dev”分支上的测试时,我将更改合并回“master”,但是有几个文件需要保留为特定于“dev”分支/服务器。
即index.php 在所有页面顶部显示“开发服务器”消息,并且没有Google Analytics 跟踪,我想保持这种方式。
还有一些配置文件在合并时不应更改。
我一直在使用cherry-pick,但这很慢而且令人沮丧......是更好的方法吗?
I'm using Git for both my development and live websites, and keep each in their own branches 'dev' and 'master'. When I finish testing on the 'dev' branch I merge my changes back to 'master', however there are several files which I need to keep specific to just the 'dev' branch / server.
I.e. index.php have a 'development server' message shown at top of all pages, and no Google Analytics tracking, and I want to keep it this way.
Also some config files which should not change when I merge.
I have been using cherry-pick, but this is slow and frustrating... is a better way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要在存储库中设置 .gitignore 文件。
基本上,您的配置文件不应添加到您的存储库中。您可以使用
.gitignore
文件来做到这一点。
假设您有一个
includes/
目录。在那里创建一个 .gitignore 文件,其中包含以下内容:这表示该目录中的 config.php 不应添加到存储库中。注意:如果文件已经添加,这将不起作用。如果已经添加,则必须 git rm 文件。
现在,由于您的存储库中根本不存在
config.php
文件,我建议创建一个config.sample.php
,它看起来与您的config 完全相同.php
文件,是您的存储库的一部分。这样,当您克隆(或其他人克隆)您的项目时,他们确切地知道配置文件中应该包含什么内容。You want to setup .gitignore files in your repo.
Basically your config files should not be added to your repo. You can use a
.gitignore
fileto do this.
Say if you have an
includes/
directory. In there make a.gitignore
file with the following in it:This says that
config.php
from this directory should not be added to the repo. Note: this will not work if the file has already been added. If it has already been added then you must git rm the file.Now since the
config.php
file won't exist in your repo at all, I would recommend creating aconfig.sample.php
which looks exactly like youconfig.php
file and is part of your repo. This way when you clone (or someone else clones) your project they know exactly what should be in the config file.