zhulink logo
自动夜间模式 日间模式 夜间模式
侧栏
0

GitHub520 | 让你告别 GitHub 打不开、图片加载慢的抓狂时刻

意外富翁的头像
|
|
|
111 专为解决GitHub访问慢、图片加载失败等问题设计,GitHub520 通过更新本地 hosts 文件,无需安装软件、配置超简单,5分钟轻松完成设置,立马加速你的 GitHub 体验! 是不是每次访问 GitHub 都像翻山越岭?尤其 clone 项目和看图时卡成 PPT?试试这个项目,简单粗暴,效果立竿见影 Github:https://github.com/521xueweihan/GitHub520 ## 手动修改 Hosts 文件 最直接的方法就是手动修改 hosts 文件。首先,从 `https://raw.hellogithub.com/hosts` 获取最新的 hosts 内容,然后根据你的操作系统,找到对应的 hosts 文件位置: * Windows: `C:\Windows\System32\drivers\etc\hosts` * Linux: `/etc/hosts` * Mac: `/etc/hosts` 使用文本编辑器(Windows 下用记事本,Linux/Mac 下用 vi 或 nano,需要 Root 权限)打开 hosts 文件,将获取到的内容复制到文件末尾,保存即可。 修改后,可能需要刷新 DNS 缓存才能生效。不同系统的刷新命令如下: * Windows: `ipconfig /flushdns` * Linux: `sudo nscd restart` 或 `sudo /etc/init.d/nscd restart` * Mac: `sudo killall -HUP mDNSResponder` 如果上述方法无效,可以尝试重启电脑。 ## 使用 SwitchHosts 自动更新 为了方便 hosts 文件的管理和更新,推荐使用 SwitchHosts 工具。在 SwitchHosts 中,添加一个 Remote hosts,配置如下: * Hosts 类型: Remote * Hosts 标题: 随意 * URL: `https://raw.hellogithub.com/hosts` * 自动刷新: 建议选择 1 小时 这样,SwitchHosts 就会自动定时更新 hosts 文件,免去手动更新的麻烦。 ## 一行命令搞定 (进阶) 对于熟悉命令行操作的开发者,可以使用一行命令来更新 hosts 文件。 **Windows (需要 Git Bash):** ```bash "C:\Program Files\Git\git-bash.exe" -c "/c/Users/XXX/fetch_github_hosts" ``` **GNU (Ubuntu/CentOS/Fedora):** ```bash sudo sh -c 'sed -i "/# GitHub520 Host Start/Q" /etc/hosts && curl https://raw.hellogithub.com/hosts >> /etc/hosts' ``` **BSD/macOS:** ```bash sudo sed -i "" "/# GitHub520 Host Start/,/# Github520 Host End/d" /etc/hosts && curl https://raw.hellogithub.com/hosts | sudo tee -a /etc/hosts ``` ## AdGuard 用户自动配置 如果你是 AdGuard 用户,也可以通过添加 DNS 封锁清单的方式来加速 GitHub 访问。在 AdGuard 的设置中,添加一个自定义列表,URL 同样是 `https://raw.hellogithub.com/hosts`,并设置更新间隔为 1 小时。 ## 效果对比与总结 通过修改 hosts 文件,可以显著提升 GitHub 的访问速度,解决图片加载问题。手动修改适合偶尔使用,SwitchHosts 和 AdGuard 适合需要长期维护的场景,一行命令适合喜欢快速操作的开发者。选择适合自己的方式,让 GitHub 飞起来吧!

▲ 赞同(0)    ★ 收藏(0)