通过Composer处理分叉的GitHub存储库 [英] Working on forked GitHub repository through Composer

查看:152
本文介绍了通过Composer处理分叉的GitHub存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的问题不太模糊,但是无法通过搜索得到正确的答案.

I hope my question is not too vague, but can't get a proper answer by searching.

我有以下情况;我们正在研究一个项目,并通过Composer安装了某些依赖项.这些依赖关系之一已经过时,需要一些修复和补充.我已在GitHub上将此仓库分叉,并将其添加到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直接在vendor文件夹中克隆该项目将不起作用,因为不会为其自动装载程序.

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.

如何以一种可以从此文件夹中提交更改的方式来处理嵌入在项目中的Composer库?

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?

推荐答案

  1. 更改composer.json中的程序包约束以使用分支而不是标记版本-您可以将dev-master用于master分支,或者将dev-my-branch用于my-branch分支.您还可以配置分支别名.

  1. Change package constraint in composer.json to use branch instead of tagged version - you can use dev-master for master branch or dev-my-branch for my-branch branch. You may also configure branch alias.

"require": {
    "some-vendor/some-package": "dev-master",
}

  • 添加一个存储库,它指向您的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:

    1. 提交您的fork中的更改并将其推送到GitHub.
    2. 返回到应用程序的根目录,然后运行composer updatecomposer require "some-vendor/some-package:dev-master".这将更新您的composer.lock文件以使用最新版本的fork.然后在您的锁中进行更改并推动.
    1. Commit changes in your fork and push them to GitHub.
    2. Go back to root of your app and run composer update or composer require "some-vendor/some-package:dev-master". This will update your composer.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存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆