Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitlab compare - get raw patch / diff file

Tags:

gitlab

My situation

In both github and gitlab, I can compare two branches or refs in the UI:

  • github: https://github.com/*/*/compare/1.x...2.x
  • gitlab: https://*.*.*/*/*/-/compare/1.x...2.x

In github, I can append .diff or .patch to this comparison, to get a raw diff or patch file.

In gitlab, this does not work.

In gitlab, I can append .patch or .diff to a single commit url like ***/-/commit/***.diff, or to a merge request url like ***/-/merge_requests/16.patch`. But it does not work on compare urls.

Why do I need this?

I like to use these patch urls in package managers like composer, so I don't have to manually create the patch file and save it somewhere.

And sometimes I don't want to apply a single commit or a complete PR/MR, but a very specific range of commits.

Question

How can I get the raw diff or patch file for a comparison in gitlab?

Version of gitlab

The instance of gitlab I tried this with is https://git.drupalcode.org/. In the help it says the version is 15.11.7-ee.

I think I had the same experience with other gitlab instances.

like image 374
donquixote Avatar asked Mar 18 '26 14:03

donquixote


1 Answers

I'm the maintainer of a Drupal Contrib Module, and was looking for this exact feature, but surprised to find that there is currently (2025) no way to do this via GitLab UI.

The only option is to download a local copy of the module's repository in question and create a diff with the git cli tool.


git clone https://git.drupalcode.org/project/MYMODULE.git
cd MYMODULE
git diff 1.x..2.x > 1.x..2.x.diff

You can add a 👍 on the open feature request to implement this:

https://gitlab.com/gitlab-org/gitlab/-/issues/217206

like image 71
JamesWilson Avatar answered Mar 21 '26 05:03

JamesWilson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!