'Get a url to a git commit from the command line

I like to share links to git commits with other people. It's useful to be able to get these without too much clicking in emacs, there is a package in emacs that I use (https://github.com/sshaw/git-link) but I want to do this from the command line.

Is there an easy way to get a link to a commit from from the command line? (I use github)

Related

git rev-parse HEAD gives you the commit from the command line



Solution 1:[1]

The URL you'd need for, say, a Bitbucket-hosted Git repository is different from the URL you'd need for a GitHub-hosted Git repository. Git itself doesn't have such links: each hosting system in use has to invent its own.

Since you want a GitHub-specific link, you can generate one, knowing that it will begin with https://github.com/ or https://raw.githubusercontent.com/. After that comes the name of the repository, e.g., git/git/. If you then want a particular file, the next part is blob/, then either a branch name or a commit hash ID, then the path to the file. The same scheme works to obtain raw file content when suing raw.githubusercontent.com.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 torek