Can you fetch old versions of a merge request?

As a reviewer, when someone pushes multiple versions of a MR, I can see all of the previous versions, and I can click on their SHAs to see the commit directly. Is there a way to fetch a specific version of the MR locally, either by the commit’s SHA or by version number? Do the old versions expire after a period of time?

I’m using a self-hosted gitlab (v13.9) for a small team (I’m not the administrator). It looks like I can still access old versions of closed/merged MRs from 6-12 months ago through the web UI, but git ls-remote doesn’t show any refs which point to them, so I wonder if they will be garbage collected at some point.

If the source branch has been deleted after an MR was merged, then although the MR will still exist in the UI, the branch will not.

That said, I may have misunderstood your question?

Yes, that’s not quite what I’m looking for.

From the Gitlab UI (at least on my instance) I can open a MR that was merged 12 months ago (and the branch was deleted when it was merged). I can then go to the “Changes” tab, and select any of the versions of the MR. We use a rebase workflow, not a merge commit workflow, so we iterate on a merge request by rewriting history on the MR branch and then force-pushing to Gitlab. Since the new versions were created by force pushing, the old versions don’t have any refs that hold onto them. However I’m still able to see them, and their contents, in the merge request UI.

I’m looking for a way to fetch these commits, which are obviously still on the server somewhere since it is able to show them to me in the web UI.

The example I gave above is for a MR that was already merged, but I’m equally interested in accessing previous versions of MRs that are still open (so that I can compare versions myself in my local workspace, e.g. use git range-diff).

Not to digress, but I recently had a scenario where I was helping someone with their MR. I force-pushed a new patch series to their branch with some fixups. They then later accidentally force pushed some changes based on an old version over my new version. I was able to piece everything together using the reflog in my local client, but it would be nicer if there was a reliable way to get the commits from Gitlab itself, in case I didn’t have them in my reflog.

Right, sorry I’m with you. I can see diffs from MRs merged two years ago in GitLab SASS, so I guess there must be a configuration option for it somewhere. Self-hosted GitLab is not something I’ve ever used, but good luck with it!

Okay, so I just found a workaround. Even though there aren’t any remotely visible refs pointing to the old commit, you can still open up the SHA in the normal commit view, e.g. From there you can choose to tag that commit (as long as you have proper permission to do so). Once the commit is tagged, then I can fetch that tag into my local repo. This definitely feel like a bit of a hack to me though, so I’d love to see a more straightforward option.