[链接文字](子文件夹路径/文件名)注意:
/(即使你在 Windows
上)。/(加 /
会变成相对于仓库根目录的绝对路径)。.md、.pdf、.png 等)。- 或下划线
_ 替代,或者用 %20
编码(但推荐避免空格)。假设你的仓库目录结构如下:
my-repo/
├── README.md ← 你正在编辑的文件
├── docs/
│ ├── guide.md
│ └── images/
│ └── screenshot.png
├── src/
│ └── main.py
└── examples/
└── demo/
└── example.md
- [使用指南](docs/guide.md)
- [查看截图](docs/images/screenshot.png)
- [主程序源码](src/main.py)
- [示例演示](examples/demo/example.md)假设你在 docs/guide.md 中,想链接到:
docs/another.mddocs/images/photo.jpgREADME.md(仓库根目录)[另一个文档](./another.md) <!-- 同级文件,推荐加 ./ -->
[查看图片](images/photo.jpg) <!-- 子文件夹 -->
[返回项目首页](../README.md) <!-- 返回上一级 -->
[返回根目录](../../README.md) <!-- 返回两级 -->推荐写法总结:
[文字](filename.md) 或
[文字](./filename.md)[文字](folder/filename.md)[文字](../filename.md) 或
[文字](../folder/filename.md)如果想链接到整个子文件夹(显示 GitHub
的树状文件列表),需要在路径最后加 /:
[查看 docs 文件夹](docs/)
[查看 examples/demo 文件夹](examples/demo/)使用 ./
明确当前目录(更清晰,推荐):
[当前文件夹下的文件](./file.md)
[子文件夹](./docs/guide.md)链接到特定行(代码文件):
[查看 main.py 的第 10 行](src/main.py#L10)链接到特定提交/分支(不推荐日常使用):
[旧版本指南](https://github.com/用户名/仓库名/blob/old-branch/docs/guide.md)| 错误写法 | 问题 | 正确写法 |
|---|---|---|
/docs/guide.md |
变成网站根目录 | docs/guide.md |
docs\guide.md |
Windows 反斜杠不支持 | docs/guide.md |
docs/guide(无扩展名) |
可能无法正确识别 | docs/guide.md |
Docs/Guide.md(大小写错) |
GitHub 对大小写敏感 | 严格匹配实际大小写 |

 <!-- 如果在 docs/ 文件夹内 -->GitHub 官方文档强烈推荐使用相对链接,因为:
小贴士:
/。