首页 > 解决方案 > 获取最近推送的提交的 github URL

问题描述

在下面的简化示例中,我有一个将提交推送到开发分支的模式:

git status // Let's see what I did
git add . // I want to commit all my changes
git commit -m "I did a thing" // I commit with a message
git pull --rebase origin dev // I am trying to avoid a merge conflict
git status // I am really ready to push, right?
git push origin dev // I am pushing to github

现在我看不出这种模式有什么问题(也许我应该?),但我想快速将链接放到我在其他地方提交的 github URL 的链接。

理想的输出,我想这就像改变这个git push输出:

To https://github.com/MyGithub/MyRepo
   aaa0001..aaa0000  dev -> dev

To https://github.com/MyGithub/MyRepo/path/to/latest/commit
   aaa0001..aaa0000  dev -> dev

标签: gitgithub

解决方案


你在用bash吗?git log使用推后的输出怎么样?

$ echo https://github.com/user/project/commit/$(git log --format="%H" -n 1)
https://github.com/user/project/commit/7e30ecbffa4ce37d0cb9e2d10682ce8fa0b24e4b

推荐阅读