为什么 Symfony/Git 忽略某些文件夹?

发布于 2025-01-10 11:25:05 字数 152 浏览 0 评论 0原文

我刚刚注意到,当我将我的 Symfony 项目推送到 Gitlab 时,某些文件夹(例如“vendor”)不会被推送(因为它们被 .gitignore 忽略)。

这是为什么呢?如果我想将项目从 Gitlab 克隆到我的另一台计算机上,那么我会丢失供应商文件夹,这不是有问题吗?

I just noticed that when I push my Symfony project to Gitlab, some of the folders (for example "vendor") are not pushed (because they are ignored by .gitignore).

Why is this? And isn't it problematic if I then want to clone the project from Gitlab onto my other computer, where I then would be missing the vendor folder?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

︶ ̄淡然 2025-01-17 11:25:05

通常,您不想在 git 中包含供应商文件夹,因为在部署时可以通过保存composer.lock文件来重建该文件夹。

您的部署应使用 Composer install 来构建供应商目录,并且它将使用与源提交中由 Composer 安装的文件相同的文件。

总结:

  • 通过修改composer.json来更改包时,请运行composer update
  • 保存/提交对composer.lock存储
  • 库克隆的更改应该运行composer install
  • composer不仅仅获取和安装依赖项——它还运行实用程序脚本,并区分生产和开发环境。它还将构建自动加载脚本以包含在您的项目中。
  • 可以随时运行composer install,因此如果需要,您可以在每次 git pull 时运行它。它应该与 git repos 具有幂等性。
  • 对于生产环境有一些选项需要考虑,例如使用 --no-dev 标志。 composer install --no-dev 这将省略任何开发库,但是,拥有一个临时环境以确保您已经在某个地方实际测试了该构建非常重要。您可能需要研究并考虑生产部署的这些附加选项:composer install --no-dev --no-scripts --optimize-autoloader。

Typically you don't want to include the vendor folder in git, as that can be rebuilt when you deploy by saving your composer.lock file.

Your deploy should use composer install to build the vendor directory, and it will use the same files as those installed by composer in your source commit(s).

In summary:

  • When changing packages via modifications to the composer.json, run composer update.
  • Save/commit changes to composer.lock
  • clones of the repo should run composer install
  • composer does more than just fetch and install dependencies -- it also runs utility scripts, and differentiates between production and development environments. It will also build the autoload script for inclusion in your project.
  • Running composer install can be done whenever you would like, so you can run it everytime you git pull if you want. It should be idempotent with git repos.
  • For a production environment there are options to consider like using the --no-dev flag. composer install --no-dev This will omit any development libraries, however, it is important to have a staging environment to insure you've actually tested that build somewhere. You might want to research and consider these additional options for a production deployment: composer install --no-dev --no-scripts --optimize-autoloader.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文