问题描述
我使用 Composer 和这个 composer.json 拉入一个包:
I pull in a package using Composer with this composer.json:
{
"require": {
"torophp/torophp": "dev-master",
},
}
当我运行 composer install
时,它似乎直接从 GitHub 拉取这个包.
When I run composer install
it seems to pull this package from GitHub directly.
我在 github 上创建了该 repo 的一个分支,并做了一些小改动.有没有办法让作曲家在 GitHub 上提取我的版本而不是原始版本?
I have created a fork of that repo on github with some small changes. Is there a way I can get composer to pull my version on GitHub instead of the original?
推荐答案
如果这是你的 composer.json
"require": {
"torophp/torophp": "dev-master"
}
如果您想更改它并使用您的 fork,只需将您的存储库添加到 composer.json
中,如下所示:
and you want to change it and use your fork instead, just add your repository into composer.json
as follows:
"repositories": [
{
"type": "vcs",
"url": "https://github.com/your-github-username/torophp"
}
]
重要:不要更改require"
部分,它必须继续使用torophp/torophp
!
Important: Do not change the "require"
part, it must continue using torophp/torophp
!
添加 "repositories"
部分后,运行 composer update
(或 composer.phar update
)然后 composer 将下载你的 fork(即使它在操作过程中回显正在安装torophp/torophp").
After adding the "repositories"
part, run a composer update
(or composer.phar update
) and composer will then download your fork (even though it echoes "installing torophp/torophp" during the operation).
更新 (18.09.2014): @efesaid 在评论中提到:
如果你的包是在packagist上发布的,你需要添加--prefer-source
选项强制从 VCS 安装.
If your package is published on packagist, you need to add
--prefer-source
option to force installation from VCS.
<小时>注意:对于那些从 HTTP(S) 源中提取问题的人(即你得到 [RuntimeException] Failed to clone https://github.com/your-github-username/torophp, 尝试更新时无法从中读取包
),您可以更改 composer.json
以改用 git 协议.为此,请按如下方式更改 composer.json
并再次运行 composer update
.
Note: For those having issues with pulling from the HTTP(S) source (ie you get
[RuntimeException] Failed to clone https://github.com/your-github-username/torophp, could not read packages from it
when trying to update), you can change the composer.json
to use the git protocol instead. To do so, change the composer.json
as follows and run composer update
again.
"repositories": [
{
"type": "git",
"url": "git://github.com/your-github-username/torophp.git"
}
]
<小时>
现在进入 vendor/torophp/torophp
并运行 git remote -v
以仔细检查您是否使用了所需的存储库源.
Now go into vendor/torophp/torophp
and run git remote -v
for a double check that you use the desired source for the repository.
从那里您可以将更改提交到您的 fork 并从源 (git pull origin master
) 更新它.<小时>更新:要使用 GitHub 上的私有存储库,您必须使用 git 协议,并且还必须为 git 客户端安装 SSH 密钥.
From there you can commit the changes to your fork and update it from origin (git pull origin master
).
Update: To work with private repositories at GitHub, you must use git protocol and also must have installed SSH keys for a git client.
Composer 参考:从 VCS 存储库加载包
Composer reference: Loading a package from a VCS repository
这篇关于更改包的 Composer git 源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!