从命令行获取 git 提交的 url
我喜欢与其他人分享 git 提交的链接。无需在 emacs 中进行太多点击即可获得这些内容非常有用,我使用的 emacs 中有一个包(https://github.com/sshaw/git-link),但我想从命令行执行此操作。
有没有一种简单的方法可以从命令行获取提交的链接? (我使用 github )
相关的
git rev-parse HEAD 为您提供来自命令行的提交
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
例如,Bitbucket 托管的 Git 存储库所需的 URL 与 GitHub 托管的 Git 存储库所需的 URL 不同。 Git 本身没有这样的链接:每个正在使用的托管系统都必须发明自己的。
由于您想要一个特定于 GitHub 的链接,因此您可以生成一个链接,并知道它将以
https://github.com/
或https:// 开头raw.githubusercontent.com/
。之后是存储库的名称,例如 git/git/。如果您想要特定的文件,下一部分是blob/
,然后是分支名称或提交哈希 ID,然后是文件的路径。在起诉raw.githubusercontent.com
时,同样的方案也可以获取原始文件内容。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/
orhttps://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 isblob/
, 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 suingraw.githubusercontent.com
.如果您的远程称为“origin”并且您使用 https 访问您的源,则此 linux 命令应该适用于 GitHub
This linux command should work for GitHub if your remote is called 'origin' and you use https to access your origin
较新版本的 Git 有一个
git remote get-url
子命令,它比git config --get
更好,特别是因为它可以解析insteadOf
。这是一个简单的脚本,它使用
get-url
获取当前存储库的基本 URL(以简单的复制和粘贴形式)。然后可以通过以下方式使用:
您可以将其配置为 git 别名,例如:
您可能对我编写的用于使
git log
包含链接的工具感兴趣:https://gist.github.com/dgl/ef848e75c03c09b0db63a43173ee5662/您的终端需要支持嵌入式超链接,但如果支持的话,您可以将其与 git log -1 结合使用> 然后只需复制提交 ID 中的链接即可。
More recent versions of Git have a
git remote get-url
subcommand which is nicer thangit config --get
, particularly because it resolvesinsteadOf
.Here is a simple script which uses
get-url
to get the base URL for the current repo (in easy copy and paste form).This can then be used via something like:
Which you could configure as a git alias, with something like:
You may be interested in a tool I wrote to make
git log
contain links: https://gist.github.com/dgl/ef848e75c03c09b0db63a43173ee5662/Your terminal will need to support embedded hyperlinks, but provided it does you can use this combined with
git log -1
and simply copy the link from the commit ID.