一、URL后缀技巧(直接改末尾)
1. .patch / .diff(最常用)
对commit、PR、compare页面,直接追加后缀,返回原始文本diff,可直接git apply打补丁。
# 单次提交
https://github.com/xxx/yyy/commit/sha1.diff
https://github.com/xxx/yyy/commit/sha1.patch
# Pull Request
https://github.com/xxx/yyy/pull/123.diff
https://github.com/xxx/yyy/pull/123.patch
# compare对比页面
https://github.com/xxx/yyy/compare/main...dev.diff
https://github.com/xxx/yyy/compare/main...dev.patch
.diff:标准git diff格式.patch:带commit元信息,可直接git apply xxx.patch
2. .raw 获取文件原始源码
文件页面末尾改为 /raw,等价页面上的Raw按钮,输出无渲染纯文本源码。
原:https://github.com/a/b/blob/main/test.py
改:https://github.com/a/b/raw/main/test.py
3. .blame 代码责任追溯
https://github.com/a/b/blame/main/test.py
绕过
.git‑blame‑ignore‑revs忽略列表:在commit sha后面加~,/blame/sha~/test.py,可以看到被屏蔽的提交记录。
4. gist专属后缀
# gist纯文本
https://gist.github.com/user/id.raw
# gist可嵌入HTML页面
https://gist.github.com/user/id.pibb
5. .keys 用户公钥页面
用户主页后加
.keys,直接拿到该用户所有上传的SSH公钥,安全审计常用。
https://github.com/username.keys
二、URL Query参数技巧(?xxx=1)
-
?w=1:忽略空白字符变更
PR/files、commit diff页面,过滤仅空格换行改动,代码评审神器。 -
?ts=N修改Tab显示宽度
设置tab渲染为N个空格,默认ts=8,常用?ts=4。 -
行号锚点
#L10#L10‑L20
点击行号自动生成,精准定位单行/多行代码片段。https://github.com/xxx/yyy/blob/main/main.py#L12
https://github.com/xxx/yyy/blob/main/main.py#L12‑L24 -
永久固定版本链接(y快捷键)
普通blob链接会随分支变动;按y,URL切换为/blob/<commit‑sha>/xxx,永久不变的固定快照链接(permalink)。
三、域名替换黑魔法
-
github.dev 网页版VS Code
仓库页面把github.com→github.dev,浏览器直接打开完整VS Code网页编辑器,等价快捷键.(英文句号)。
快捷键:仓库页面英文输入法直接按
.一键跳转github.dev。
-
github1s(第三方,非官方)
四、Compare高级对比URL语法
-
分支/提交对比
A分支到B分支
https://github.com/user/repo/compare/main...feature
跨fork对比:别人仓库的分支 和自己仓库对比
https://github.com/my/repo/compare/otheruser:theirbranch...mybranch
时间对比:master一天前 vs 当前master
https://github.com/user/repo/compare/master@{1.day.ago}...master
指定日期对比
https://github.com/user/repo/compare/master@{2026‑01‑01}...master
末尾追加.diff/.patch直接拿diff文本。
五、网页端键盘快捷键(仓库页面)
| 快捷键 | 功能 |
|---|---|
t |
快速文件搜索,输入文件名跳转文件 |
y |
切换为commit‑sha永久链接(permalink) |
.(句号) |
打开github.dev网页VSCode |
l |
快速跳转到行号 |
s |
聚焦搜索框 |
g i |
跳转到Issues页面 |
g p |
跳转到Pull requests页面 |
b |
切换分支选择框 |
shift + ←/→ |
diff页面切换文件 |
六、提交与Issue小技巧
- commit message写
Fixes #123,合并PR后自动关闭issue。 - 评论中粘贴带
#Lxx代码片段链接,会自动渲染预览代码片段。
七、安全审计场景实用组合
- 拿用户SSH公钥:
https://github.com/{username}.keys - 批量获取提交补丁:遍历commit url拼接
.patch,脚本批量下载分析历史泄露密钥。 ?w=1过滤大量格式化commit,找真实业务改动。- blame加
~绕过.git‑blame‑ignore‑revs看被隐藏的历史提交。
补充注意
.keys只返回用户上传的SSH公钥,不是GPG密钥;GPG密钥需要访问用户设置页面API获取。.patch/.diff仅公开仓库有效;私有仓库需要登录授权。- github.dev 需要登录github账号;github1s第三方不需要登录。