如何将特定标签/版本与作曲家和私有 git 存储库一起使用?如何将、作曲家、版本、标签

2023-09-06 15:35:41 作者:野心段子手

我在我公司的 Gitlab 上托管了一些软件包.我想请求这些包的特定版本,但每次尝试时,composer 都会下载 master 分支的最新提交.

I've got some packages host on the Gitlab of my company. I want to request a specific version of these packages but each time I try, composer download the latest commit of the master branch.

composer.json:

composer.json :

{
   "name" : "MyProject",
   "require" : {
      "user/project" : "v0.5.0"
   },
   "type" : "project",
   "repositories" : [
      {
         "url" : "git@gitlab.XXXX.fr:user/project.git",
         "type" : "vcs"
      }
   ],
   "config" : {
      "vendor-dir" : "private/class"
   }
}

我的包的仓库结构:

标记 v0.5.0:提交 dd6ed3c8...提交 X,Y,Z标记 v0.7.0:提交 15293ac6...最后一次提交 f15600a1...

当我执行composer install"时:

When I execute "composer install" :

使用包信息加载作曲家存储库

Loading composer repositories with package information

安装依赖(包括require-dev)

Installing dependencies (including require-dev)

分析69个包解决依赖关系

Analyzed 69 packages to resolve dependencies

解析67条规则解决依赖

Analyzed 67 rules to resolve dependencies

安装用户/项目(dev-master f15600a) csdn测开涨薪技术 Git原理及使用全套教程

Installing user/project (dev-master f15600a)

克隆 f15600a1

Cloning f15600a1

它只下载最后一次提交.

It downloads the last commit only.

如何配置项目的 composer.json 文件以使用特定标签?

How can I configure the composer.json file of my project to use a specific tag ?

推荐答案

如何要求特定的 Git 标签?

将版本要求更改为 dev-master,后跟散列 # 和 Git 标记名称,例如v0.5.0,像这样:

Change the version requirement to dev-master, followed by a hash # and the Git tag name, e.g. v0.5.0, like so:

"require": {
    "vendor/package": "dev-master#v0.5.0"
}

如何要求特定的 Git 提交?

将版本要求更改为 dev-master,后跟散列 # 和 Git 提交参考,例如dd6ed3c8,像这样:

Change the version requirement to dev-master, followed by a hash # and the Git commit reference, e.g. dd6ed3c8, like so:

"require": {
    "vendor/package": "dev-master#dd6ed3c8"
}

参考:https://getcomposer.org/doc/04-schema.md#package-links

定义您自己的包并设置版本和参考

使用 "type": "vcs" 的存储库的另一种方法是在存储库中定义自定义包 "type": "package" 并使用参考.

An alternative to working with repositories of "type": "vcs" is to define a custom package "type": "package" inside repositories and work with a reference.

引用可以是 Git 提交哈希,也可以是标签或分支名称,例如 origin/master.

The reference is either a Git commit hash, or a tag or branch name, like origin/master.

这会将 version 绑定到特定的提交 reference,在本例中为 dd6ed3c8.

This will tie the version to a specific commit reference, in this case dd6ed3c8.

"repositories": [
  # ...
  {
    "type": "package",
    "package": {
      "name": "vendor/package",
      "version": "v0.5.0",
      "source": {
        "url": "git@gitlab.server.com:vendor/project.git",
        "type": "git",
        "reference": "dd6ed3c8"
      }
    }
  }
]