Generating a link to the compare diff result of a single file

I understand that there is a compare API where you can provide a commits or branches for comparison.

This returns the diffs fine but what I’d like to generate next is a link to a GitLab compare page to a given file. Say I have a commit change that’s modified 3 files, I want to provide a URL link to the diff of the last file say.

I see on the Compare web page that there is a dropdown like ‘Showing 2 changed files’ which provides links to the differing files. I’d like to reference these links too but I can’t see where the last hash in the URL’s are coming from to derive it in my code.



I thought that the sha after the # would be just be the blob Id but it doesn’t seem to be. Any suggestions?