git 根据提交哈希在 GitHub 上查找提交
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12214746/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Find a commit on GitHub given the commit hash
提问by dopplesoldner
I am fairly new to Github and have come across an amateur-ish problem.
我对 Github 相当陌生,并且遇到了一个业余问题。
I have been asked to do a code review and have been provided with a commit hash, however I have tried looking in Git if I can search using commit hashes but couldn't find anything.
我被要求进行代码并获得了提交哈希,但是我尝试在 Git 中查找是否可以使用提交哈希进行搜索但找不到任何内容。
Is there a way I can find the changed code just by using the commit hash?
有没有办法仅通过使用提交哈希就可以找到更改的代码?
回答by Matt McHenry
A URL of the form https://github.com/<owner>/<project>/commit/<hash>
will show you the changes introduced in that commit. For example here's a recent bugfix I made to one of my projects on GitHub:
表单的 URLhttps://github.com/<owner>/<project>/commit/<hash>
将显示该提交中引入的更改。例如,这是我最近对 GitHub 上的一个项目进行的错误修复:
https://github.com/jerith666/git-graph/commit/35e32b6a00dec02ae7d7c45c6b7106779a124685
https://github.com/jerith666/git-graph/commit/35e32b6a00dec02ae7d7c45c6b7106779a124685
You can also shorten the hash to any unique prefix, like so:
您还可以将哈希缩短为任何唯一前缀,如下所示:
https://github.com/jerith666/git-graph/commit/35e32b
https://github.com/jerith666/git-graph/commit/35e32b
I know you just asked about GitHub, but for completeness: If you have the repository checked out, from the command line, you can achieve basically the same thing with either of these commands (unique prefixes work here too):
我知道您刚刚询问了 GitHub,但为了完整起见:如果您已检出存储库,则从命令行,您可以使用以下任一命令实现基本相同的功能(唯一前缀也可在此处使用):
git show 35e32b6a00dec02ae7d7c45c6b7106779a124685
git log -p -1 35e32b6a00dec02ae7d7c45c6b7106779a124685
Note: If you shorten the commit hash too far, the command line gives you a helpful disambiguation message, but GitHub will just return a 404.
注意:如果您将提交哈希缩短得太远,命令行会为您提供有用的消歧消息,但 GitHub 只会返回 404。
回答by qwertzguy
View single commit:https://github.com/<user>/<project>/commit/<hash>
查看单个提交:https://github.com/<user>/<project>/commit/<hash>
View log:https://github.com/<user>/<project>/commits/<hash>
查看日志:https://github.com/<user>/<project>/commits/<hash>
View full repo:https://github.com/<user>/<project>/tree/<hash>
查看完整的回购:https://github.com/<user>/<project>/tree/<hash>
<hash>
can be any length as long as it is unique.
<hash>
可以是任何长度,只要它是唯一的。
回答by Todd Owen
The ability to search commitshas recently been added to GitHub.
对能力的搜索提交最近被添加到GitHub上。
To search for a hash, just enter at least the first 7 characters in the search box. Then on the results page, click the "Commits" tab to see matching commits (but only on the default branch, usually master
), or the "Issues" tab to see pull requests containing the commit.
要搜索哈希,只需在搜索框中输入至少前 7 个字符即可。然后在结果页面上,单击“提交”选项卡以查看匹配的提交(但仅在默认分支上,通常为master
),或单击“问题”选项卡以查看包含提交的拉取请求。
To be more explicit you can add the hash:
prefix to the search, but it's not really necessary.
为了更明确,您可以将hash:
前缀添加到搜索中,但这并不是必需的。
There is also a REST API(at the time of writing it is still in preview).
还有一个REST API(在撰写本文时它仍处于预览阶段)。