# 在 Confluence 中显示某个分支、标签或提交中的 GitHub 文件 要在 Confluence 中显示某个分支、标签或提交中的 GitHub 文件,请在 github.com 上切换到该分支、标签或提交并打开文件,复制链接,然后粘贴到页面中或选择器的搜索框中。宏会从链接中读取引用(ref)。选择器自身的浏览功能始终使用仓库的默认分支。 --- ## 开始之前 * 您可以编辑该 Confluence 页面。 * 您已经知道想要哪个分支、标签或提交。标签或提交会使文件内容固定不变;分支则会跟随其最新提交。 --- ## 步骤 1. 在 github.com 上打开文件,使用分支菜单切换到所需的分支或标签。若需要固定版本,请改为从某个提交中打开文件。 2. 复制地址。它类似于 `https://github.com/owner/repo/blob/v2.1.0/docs/setup.md`。 3. 编辑 Confluence 页面,并在空行上粘贴链接。它会变成 **Github file (Capable)** 宏。 4. 如果要改为修改现有宏,请打开其配置,将链接粘贴到 **Search repositories or paste URL...** 中,按 Enter 键,然后选择 **Add to page**。 5. 发布页面。 --- ## 后续会发生什么 宏标题中会在路径后用括号显示引用(ref),例如 `(v2.1.0)`。对于 `main` 则不显示任何内容。分支会随着人们提交而不断变化;标签或提交链接则会显示相同的内容,直到您更改宏。 ⚠️ 请使用简短的 `/blob//` 形式。完整写出 `/blob/refs/heads/main/...` 的链接会被转换为无法正常工作的宏。请参阅[此故障排除页面](https://help.gocapable.com/zh-hans/git/pasted-a-link-like-github-com-owner-repo-blob-refs-heads-main-file-md-and-the-macro-is-broken.html)。 --- ## 如果仍然无法解决 * 诸如 `#L10-L20` 的行范围会被忽略,并显示整个文件。请参阅[粘贴了带有行范围的链接](https://help.gocapable.com/zh-hans/git/pasted-a-link-with-a-line-range-like-l10-l20-but-the-whole-file-is-shown.html)。 * 选择器中没有分支列表,这是正常现象。请参阅[无法在 Browse GitHub 选择器中选择其他分支](https://help.gocapable.com/zh-hans/git/cannot-choose-a-different-branch-in-the-browse-github-picker.html)。 --- ## 相关内容 ### [自动转换粘贴的 GitHub 链接](https://help.gocapable.com/zh-hans/git/auto-convert-pasted-github-links.html) 哪些链接会被转换,以及转换方式。 ### [Github 文件](https://help.gocapable.com/zh-hans/git/github-file.html) 所有设置项以及宏的显示内容。 ### [在 Confluence 中嵌入 GitHub 文件](https://help.gocapable.com/zh-hans/git/embed-a-github-file-in-confluence.html) 基本任务,从头到尾。 ### [宏在仍使用 master 的仓库中找不到文件](https://help.gocapable.com/zh-hans/git/macro-cannot-find-a-file-in-a-repository-that-still-uses-master.html) 仍使用 master 的仓库。 --- _每次都是您想要的版本。_