如何使用 cli 获取 Github 最新提交 url?
示例输出:https : //github.com/my_user/my_repo/commit/0904dcc315ec80d024440dda5208ebf1d7edbcb3
我发现的最接近的是git rev-parse HEAD
它返回最新的提交但不返回完整的 github url。
我使用powershell
(pwsh) 作为终端。
我还安装了Github CLI和git
.
当您使用 PowerShell 时,只需将该提交哈希插入您的 URL:
"https://github.com/my_user/my_repo/commit/$(git rev-parse HEAD)"
为了使其更加灵活,您可以执行以下命令:
"$($(git config --get remote.origin.url) -ireplace '\.git$', '')/commit/$(git rev-parse HEAD)"
这应该适用于从github克隆的所有存储库,而不仅仅是您的特定存储库。
您可以将其写入一个函数并将其添加到您的个人资料中,以便更快/更轻松地获取 URL:
function Get-GitUrl {
return "$($(git config --get remote.origin.url) -ireplace '\.git$', '')/commit/$(git rev-parse HEAD)"
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句