使用 Git 管理框架,忽略第一次拉取后对给定文件的更改
我正在使用 git 来管理扩展的 CodeIgniter 框架。它是当前 CI 版本的克隆,带有额外的帮助程序、库等。
我有许多网站都使用此框架,如果我添加新的帮助程序方法或修复一个网站中的错误,我希望能够轻松更新所有其他网站,而无需覆盖其任何自定义文件。
我希望实现以下工作流程
- 创建一个新的站点目录
git init
来初始化一个空白的本地 git 存储库 - 将其与远程框架存储库链接
git remote add origin [email protected]:username/framework_repo
- 提取远程框架的新副本
git pull origin master
- 对站点文件进行更改并将其提交回远程存储库
git push origin master
- 将这些更改拉到其他站点
- 重复步骤 4 和 4 5
没问题,但是:
- 像 config.php 和 database.php 这样的文件永远不应该提交回远程存储库,因为它们对于每个站点都是唯一的。
- 但是我希望它们存在于远程存储库中,因此在第一个拉取请求时,默认文件会下载到我的本地目录。
- 此外,如果我从远程存储库再次拉取以更新框架,我不希望这些文件被覆盖
实现此目的的最佳方法是什么?一些 .gitignore 巫毒? 我已经使用 .gitignore 来忽略文件,但在这种情况下,它略有不同,因为我只想在第一个请求时提取文件。
我希望这是有道理的。
I'm using git to manage an extended CodeIgniter Framework. It's a clone of the current CI release with extra helpers, libraries ect.
I have many sites all using this framework and if I add a new helper method or fix a bug in one site I want to be able to easily update all the other sites without overwriting any of their custom files.
I wish to achieve the following workflow
- Create a new site directory
git init
to initialise a blank local git repo - Link this with the remote framework repo
git remote add origin [email protected]:username/framework_repo
- Pull a fresh copy of the remote framework
git pull origin master
- Make changes to site files and commit them back to the remote repo
git push origin master
- Pull these changes down to the other sites
- Repeat steps 4 & 5
Thats all fine, BUT:
- Files like config.php and database.php should never be committed back to the remote repo as they are unique to each site.
- However I want them to exist in the remote repo so on the first pull request the default files are downloaded to my local directory.
- Further more if I do another pull from the remote repo to update the framework I do not want these files to be overwritten
Whats the best way to achieve this? Some .gitignore voodoo?
I already use .gitignore to ignore files, but in this case its slightly different as I want to pull the file only on the first request.
I hope that makes sense.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
将所有不应该在存储库中的文件放入
.gitignore
文件中。这几乎不是任何巫术,它只是一个应该被忽略的文件列表。创建诸如 config.default.php 之类的虚拟文件,并在第一次拉取后将其复制到忽略的名称。
完成第一个步骤!
Put all the files that shouldn't be in the repo to the
.gitignore
file. That is hardly any vodoo, it's just a list of files that should be ignored.create dummy files like
config.default.php
and copy them after the first pull to the ignored name.done with the first to steps!
config.php-dist
post-receive
,如下所示。post-receive
示例(根据您的需求定制):config.php
to your.gitignore
.config.php-dist
post-receive
, like below.git pull
, but the copy will only be done whenconfig.php
does not exist.post-receive
example (tailor to your needs):我认为您想要的是每个自定义站点的多个分支以及公共文件的额外上游分支。每个分支所在的位置(或者如果您有它的多个副本)实际上并没有太大区别。
当您对公共文件进行更改时,您可以直接在公共分支上进行更改,也可以在自定义分支之一上创建签入,然后将其挑选到公共分支上。您不想将更改推送到公共分支,因为这将需要自定义和修复。从公共分支拉取到自定义分支是安全的,因为您所做的任何更改都将被合并。
I think what you want is a number of branches for each customised site and an extra upstream branch for the common files. It doesn't really make much difference where each branch lives (or if you've got multiple copies of it).
When you make a change to the common files, you can either make it directly on the common branch or create a checkin on one of the customised branches then cherry-pick it onto the common branch. You don't want to push changes to the common branch, because that will take the customisations as well as the fixes. It's safe to pull from the common branch to the customised branches, as any changes you've made will be merged in.