问题描述
我正在编写一个可用于未来项目的框架.我想将框架放到私人托管的git服务器上,并在以后的项目中用composer加载它.
I am writing a framework which is usable for my future projects.I would like to put the framework to a privately hosted git server, and load it with composer in my future projects.
我可以在进行git init时知道使用"--bare"吗?我曾经创建裸"仓库,但作曲家说找不到该软件包.我到处搜索,并认为这是由于缺少composer.json"造成的.但是,如果没有"--bare",我什至无法将我的代码推送到服务器.我将框架"git clone"到另一个位置,并使用composer加载该位置,仍然失败.
May I know when I git init, should "--bare" be used?I used to create "bare" repo, but composer said the package is not found. I have searched around, and believe it is due to "missing of composer.json".However, without "--bare", I can't even push my code to server. I "git clone" the framework to another location, and load the location with composer, still failed.
我尝试了以下两个版本,但都失败了:
I have tried the two versions below, both failed:
"repositories": [
{
"type": "vcs",
"url": "https://server/git/sdk/"
}
]
"repositories": [
{
"type": "package",
"package": {
"name": "vendor/sdk",
"version": "master",
"source": {
"url": "https://server/git/sdk/",
"type": "git",
"reference": "master"
}
}
}
]
谢谢.
推荐答案
我正在参考有关如何从VCS加载程序包的官方文档: https://getcomposer.org/doc/05-repositories.md#using-私有存储库
I'm referencing the offical docs on how to load a package from a VCS:https://getcomposer.org/doc/05-repositories.md#using-private-repositories
要请求私有项目B,您需要在公共项目A的 composer.json
文件中有两件事:
To require private project B you need two things in the composer.json
file of public project A:
- 将存储库定义为类型
vcs
,其中包含服务器上专用存储库的URL -
需要
- define the repository as type
vcs
with the URL to the private repository at your server require it
{
"name": "project A",
"description": "public project A requiring private project B",
"require": {
"vendor/my-private-repo": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "[email protected]:vendor/my-private-repo.git"
}
]
}
然后运行Composer.它将私有项目B提取到项目A的供应商文件夹中.
Then run Composer. It will fetch the private project B into the vendor folder of project A.
git init --bare
创建一个没有工作树的存储库.这意味着存储库不包含源文件的有效副本或已检出副本.只有您的仓库的git修订历史记录存储在存储库的根文件夹中(而不是.git子文件夹中).
git init --bare
creates a repository without a working tree. That means the repository contains no working or checked out copy of your source files. Only the git revision history of your repo is stored in the root folder of your repository (instead of in a .git subfolder).
您不需要 git clone
或 git init
存储库来存储本地副本,只需使用Composer直接从私有服务器中获取.
You don't need to git clone
or git init
the repository to store a local copy, just fetch directly from the private server with Composer.
我们有以下情况:
- 具有
- 项目A应该从私有存储库中提取项目B.
- 我们将git保留在外,让Composer进行提取.不要手动获取.
- 仅关注解决此问题的
composer.json
一侧(请参见上文)
composer.json
的- project A with a
composer.json
should fetch project B from private repo. - we are leaving git out, let Composer do the fetching. Do not fetch manually.
- and focus only on the
composer.json
side of to solve this issue (see above)
旁注:您发布的第二个存储库
定义定义了一个 package
.这在 https://getcomposer.org/doc/05-repositories.md中进行了描述#package-2 您可以自由地将私有存储库作为一个软件包,但此处不需要,因为上面的 composer.json
应该可以正常工作.
Sidenote: the second repository
definition you posted defines a package
.This is described in https://getcomposer.org/doc/05-repositories.md#package-2You are free require the private repo as a package, but its not needed here because the above composer.json
should work just fine.
这篇关于用composer加载一个自定义的git仓库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!