This is really more a question about GitHub than it is about Git.
Remember, Git itself is all about commits. Each commit stores some data—a snapshot of a set of files—and some metadata, including stuff like who made the commit, when, and why. Each of these commits is uniquely identified by its hash ID. Branch and tag names, if any such names exist, merely serve to find some particular hash ID to get you—or Git—started as one of the metadata items in any commit is a list of parent hash IDs, so that Git can start at the last commit and work backwards.
Commits, with their stored data and metadata, are the reason Git exists. Each Git repository is a collection of commits, plus some ancillary data to help find commits. (A non-bare repository on your computer also provides you with a work-area in which you can do new work, but the commits and ancillary data, which don't let you do new work here, are the bare minimum.)
GitHub, on the other hand, is not about commits. GitHub is about sharing.1 This sharing uses (bare) Git repositories, but adds a ton more stuff on top of that. The Git repositories—or some kind of repository anyway2—are necessary to this, but are not the added-value part.
As GitHub try to increase their added value, they start adding things like: Here's a convenient way to access one particular file within one particular commit. Your interface to GitHub is an API, and that API is encoded via HTTP/HTTPS. That means URLs and JSON and so on.
In this case, GitHub have invented some particular URL paths (see the anatomy of a URL) that can refer to a file within a commit. They have provided one way to use a commit hash ID plus a file-path-within-commit to access that file in that specific commit, and another way to use a branch name (such as master
) plus a file-path-within-commit to access that file in the commit identified by that branch name.
To do this in Git, you'd normally just git checkout
the branch name—which puts the entire commit into your work-tree—and then look at the file by its OS-level path, which is derived from its in-Git-commit path.3 But perhaps your question is: How can I view one file from one commit identified by branch name? In which case, try git show
:
git show master:path/to/File.ext
will let you view the file stored under that name (path/to/file.ext
) from that commit (whatever hash ID the name master
resolves to).
1Sharing and and archival (off-site storage). Two! Our two principle weapons are...
2Remember that Bitbucket was once a Mercurial repository sharing site. It held Hg repos, not Git repos. Perhaps someday GitHub will hold some other kind of repository.
3The OS-level path might differ from the in-Git path in several ways. For instance, on a typical Windows system, filename case (upper or lower case) is only half-respected, so a Git file named path/to/File.ext
might reside in a Windows OS file system under path/TO/file.EXT
. A typical MacOS file system enforces certain decomposition rules on UTF-8 strings, so MacOS might change a Git file's path as well. Linux tends not to interpret UTF-8, so if Git uses an invalid UTF-8 byte-sequence as a file path name, Linux has no issues at all here.