问题描述
希望我的问题不要太含糊,但不能通过搜索得到正确答案.
I hope my question is not too vague, but can't get a proper answer by searching.
我有以下情况;我们正在开发一个项目,并通过 Composer 安装了某些依赖项.其中一个依赖项已经过时,需要一些修复和添加.我已经在 GitHub 上 fork 这个 repo 并将其添加到 Packagist.
I have the following situation; We are working on a project and have certain dependencies installed through Composer. One of these dependencies is quite outdated and requires some fixes and additions. I have forked this repo on GitHub and added it to Packagist.
要处理代码,我需要它在我的项目中运行并从那里编辑以查看我的更改是否有效,但它位于 vendor
文件夹中,它是通过 composer 安装的.
To work on the code, I need it running in my project and edit from there to see if my changes work, but it is in the vendor
folder, where it is installed through composer.
无法通过 GitHub 直接在供应商文件夹中克隆此项目,因为不会为其编写自动加载器.
Cloning this project through GitHub directly in the vendor folder won't work, as the autoloader won't be written for it.
到目前为止,我所做的是在 vendor
文件夹中工作,然后将我的工作从那里复制并粘贴到 GitHub 文件夹并从那里推送,但逻辑上相当棘手.
What I have done so far is working in the vendor
folder, and then copying and pasting my work from there to the GitHub folder and pushing from there, but logistically quite tricky.
如何处理嵌入在项目中的作曲家库,以便您可以从该文件夹提交更改?
How does one work on a composer library that is embedded in a project, in such a way that you can commit your changes from this folder?
推荐答案
更改
composer.json
中的包约束以使用分支而不是标记版本 - 您可以将dev-master
用于master
my-branch
分支的分支或dev-my-branch
.您还可以配置分支 别名.
Change package constraint in
composer.json
to use branch instead of tagged version - you can usedev-master
formaster
branch ordev-my-branch
formy-branch
branch. You may also configure branch alias.
"require": {
"some-vendor/some-package": "dev-master",
}
添加一个 repository 指向你的 fork:
Add a repository which points to your fork:
"repositories": [
{
"type": "git",
"url": "https://github.com/richard/some-package/"
},
]
运行 composer update
从你的 fork 安装新版本(或者 composer require "some-vendor/some-package:dev-master"
如果你不'不想更新任何其他依赖项).
Run composer update
to install new version from your fork (or composer require "some-vendor/some-package:dev-master"
if you don't want to update any other dependencies).
现在您应该已经从 vendor/some-vendor/some-package
中的 fork 克隆了源代码.您可以编辑这些文件并测试更改是否适合您的应用.完成工作后:
Now you should have sources cloned from your fork in vendor/some-vendor/some-package
. You can edit these files and test if changes fits to your app. After you finish your work:
- 在您的 fork 中提交更改并将其推送到 GitHub.
- 返回应用的根目录并运行
composer update
或composer require "some-vendor/some-package:dev-master"
.这将更新您的composer.lock
文件以使用最新版本的 fork.然后提交更改并推送.
- Commit changes in your fork and push them to GitHub.
- Go back to root of your app and run
composer update
orcomposer require "some-vendor/some-package:dev-master"
. This will update yourcomposer.lock
file to use latest version of your fork. Then commit changes in your lock and push.
现在,如果有人将克隆您的项目(或只是提取更改),它将获得新的 composer.lock
指向具有指定提交哈希的 fork - composer install
应该始终直接从 GitHub 安装相同版本的 fork.
Now if someone will clone your project (or just pull changes) it will get new composer.lock
pointing to your fork with specified commit hash - composer install
should always install the same version of your fork directly from GitHub.
这篇关于通过 Composer 处理分叉的 GitHub 存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!