使用 Git 管理框架,忽略第一次拉取后对给定文件的更改

发布于 2024-09-07 04:43:30 字数 923 浏览 7 评论 0原文

我正在使用 git 来管理扩展的 CodeIgniter 框架。它是当前 CI 版本的克隆,带有额外的帮助程序、库等。

我有许多网站都使用此框架,如果我添加新的帮助程序方法或修复一个网站中的错误,我希望能够轻松更新所有其他网站,而无需覆盖其任何自定义文件。

我希望实现以下工作流程

  1. 创建一个新的站点目录 git init 来初始化一个空白的本地 git 存储库
  2. 将其与远程框架存储库链接 git remote add origin [email protected]:username/framework_repo
  3. 提取远程框架的新副本 git pull origin master
  4. 对站点文件进行更改并将其提交回远程存储库 git push origin master
  5. 将这些更改拉到其他站点
  6. 重复步骤 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

  1. Create a new site directory git init to initialise a blank local git repo
  2. Link this with the remote framework repo git remote add origin [email protected]:username/framework_repo
  3. Pull a fresh copy of the remote framework git pull origin master
  4. Make changes to site files and commit them back to the remote repo git push origin master
  5. Pull these changes down to the other sites
  6. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

归途 2024-09-14 04:43:30
  • 永远不要提交像 config.php 和 database.php 这样的文件
    按原样返回远程仓库
    每个网站都是独一无二的。

将所有不应该在存储库中的文件放入 .gitignore 文件中。这几乎不是任何巫术,它只是一个应该被忽略的文件列表。

  • 但是我希望它们存在于远程存储库中,所以在第一次拉取时
    请求默认文件是
    下载到我的本地目录。

创建诸如 config.default.php 之类的虚拟文件,并在第一次拉取后将其复制到忽略的名称。

  • 如果我从远程存储库再次拉取以更新
    我不希望这些文件
    被覆盖

完成第一个步骤!

  • Files like config.php and database.php should never be committed
    back to the remote repo as they are
    unique to each site.

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.

  • 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.

create dummy files like config.default.php and copy them after the first pull to the ignored name.

  • Further more if I do another pull from the remote repo to update the
    framework I do not want these files to
    be overwritten

done with the first to steps!

神魇的王 2024-09-14 04:43:30
  1. 将 config.php 添加到您的 .gitignore 中。
  2. 创建要使用的 default/distribution/base 配置,config.php-dist
  3. 创建一个 Git 挂钩,post-receive,如下所示。
  4. 该钩子将在每次 git pull 后执行,但只有当 config.php 不存在时才会执行复制。

post-receive 示例(根据您的需求定制):

#!/bin/bash
[ -f 'config.php' ] || cp config.php-dist config.php
  1. Add config.php to your .gitignore.
  2. Create the default/distribution/base configuration to use, config.php-dist
  3. Create a Git hook, post-receive, like below.
  4. The hook will execute after each git pull, but the copy will only be done when config.php does not exist.

post-receive example (tailor to your needs):

#!/bin/bash
[ -f 'config.php' ] || cp config.php-dist config.php
勿忘初心 2024-09-14 04:43:30

我认为您想要的是每个自定义站点的多个分支以及公共文件的额外上游分支。每个分支所在的位置(或者如果您有它的多个副本)实际上并没有太大区别。

当您对公共文件进行更改时,您可以直接在公共分支上进行更改,也可以在自定义分支之一上创建签入,然后将其挑选到公共分支上。您不想将更改推送到公共分支,因为这将需要自定义和修复。从公共分支拉取到自定义分支是安全的,因为您所做的任何更改都将被合并。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文