Can I pull a specific commit with composer? Can I pull a specific commit with composer? git git

Can I pull a specific commit with composer?


You can't reference a pull request directly, but you can always get hold of a specific commit. You just need to find the commit hash that the pull request introduces. (If you're using github it's in the commits tab).

Then you'll need to use something like this in your composer.json -

 "require": {    "mysoftware/thesoftware": "dev-master#3f38376d"}

Where mysoftware/thesoftware is the usual vendor/software name thing you would use, and the part after the '#' on the right-hand side is the specific commit hash you want.


The suggested and approved solution works to download commits already merged on the main repository.

IF YOU WANT TO DOWNLOAD A COMMIT FROM A PULL REQUEST NOT YET MERGED you have to follow a different path.

Suppose you have the package vendor/package and that "RandomUser" creates a fork on GitHub, creates a new branch patch-1 and commits to it some editing that you want to test downloading them via composer.

Then, your composer.json file has to be written this way:

{    "type": "project",    "license": "proprietary",    "require": {        ...        "vendor/package": "dev-patch-1#1234567890",        ...    },    ...    "repositories": [        {            "type": "vcs",            "url": "https://github.com/RandomUser/Package.git"        }    ]}

As you can see, in the require section of the composer.json file you request the package as usual, BUT you add the specific branch dev-patch1, prefixing it with dev- to decrease the minimum stability to dev, and adding the #1234567890 the specific commit ID.

Then you also add the specific repository of the user that committed the PR: this makes Composer able to download the git repository, check the existent branches on it, read its composer.json file and use it to install you required dependency.


Yes: you just need the commit ID. Say you want to pull in this commit to Ardent (Laravel framework, PHP) - you can force it to that commit with

"require": {    "laravelbook/ardent": "master#9fbe73399d84fc726dc9e122955de444f4fb4901"}

To pull from a fork, you just need to specify that fork in the require instead. For example, this is one of my forks of another repo. To get that commit, I can require this

"require": {    "JoeChilds/Swiftlet": "master#effd5c59f398d56fec261cf1d73a7397cdf78a56"}