Search code examples
gituriurl-scheme

Is there a Git URI scheme that lets me reference a file in a repo at a specific commit?


The git Resource Identifier Scheme lets me reference a specific git repository.

However, I'm looking for a URI scheme that lets me reference a specific file/folder, at a specific commit, in a specific git repo. For example, the figurative URI git://github.com/torvalds/linux.git:usr/Makefile@a30d8a39f0571425a459816ed8680e987a2ff279 could be used to reference the file usr/Makefile in the repository git://github.com/torvalds/linux.git at commit a30d8a39f0571425a459816ed8680e987a2ff279. Is there a standard URI scheme that achieves this?

To be clear, I'm interested in a URI scheme that works for all git servers, not e.g. a HTTP URL that works for e.g. GitHub or GitLab only.


Solution

  • I am not aware of any widely accepted way to do this, but here is a scheme that I proposed years ago: http://www.nuke24.net/docs/2014/GitObjectURIScheme.html.

    Generally, the form is x-git-object:ef967a26bcd39ca62dd687e929ba4eba0ae66e81, which references the object identified by that Git hash (which in this case is the content of Linux's Makefile, but could otherwise be a commit or tree, which are not directly representable as strings/byte sequences). That document also specifies ways to suggest a repository and to reference the latest on a named branch or a path within a tree or commit, so you could say x-git-object:latest?branch=master&repository=git://github.com/torvalds/linux.git#Makefile to reference the Makefile in the latest commit on the master branch, whatever it may be.