问题描述
更新:这是针对此问题的。
我在单独的Git分支( screenshot.png ) > assets ),用于README.md文件(位于 master
分支)。
要在GitHub上查看图像,我必须链接到:
/../ assets / screenshot。 png
或
../ assets / screenshot.png
但是,查看时不起作用在本地自述文件中,图像不会显示(例如在VS Code或Atom中使用Markdown预览功能时)。
我甚至使用了 git worktree 功能来检查 assets 子目录中的 assets 分支:
git worktree add -B资产资产来源/资产
所以目录结构就像这样:
.git
资产
assets / screenshot.png
README.md
这意味着,为了在README文件中本地查看图像,我必须链接到
/assets/screenshot.png
或
assets / screenshot.png
如何协调这两个worlds?
是否有链接到屏幕截图的方法,因此总是显示我是否在GitHub本身或本地查看文档,使用不同的标记渲染器?
不,这是不可能的,你不应该指望它。
你应该让资产文件夹成为你主分支的一部分,否则你应该分离将这两个存储到不同的存储库中,或者沿着这些线存储。
GitHub服务此屏幕截图的原因很充分,但好理由只是一个相关的技术原因以及GitHub如何为您的存储库提供内容。
让我们看看您的屏幕截图的URL,就像您在主要存储库页面中提供的HTML中使用的那样:
https://raw.githubusercontent.com/devliber/ReadmeScreenshotBranch/assets/screenshot.png
正如您所看到的,带图像的分支名称是URL的一部分。让我们尝试将网址反馈回您的自述文件:
https://raw.githubusercontent.com/devliber/ReadmeScreenshotBranch/master /README.md
如果您尝试使用此网址,您会看到它显示您的自述文件。 p>
所以这里的问题是你从另一个分支获得截图的黑客是你得到这个URL:
https://raw.githubusercontent.com/devliber/ReadmeScreenshotBranch/master/../assets/screenshot.png
这解析为与我在这里发布的第一个网址完全相同的网址,这就是您看到图片的原因。
但是,如果您签出分支X,则不应期望分支Y中的任何内容出现在您的工作文件夹中。它在GitHub上工作的原因是它们提供来自分支机构的内容,但它不会,不应在本地工作,除非您开始使用工作区检出多个分支。
Update: This is the GitHub test repository for this question.
I'm storing a screenshot (screenshot.png
) in a separate Git branch (assets
), to be used in a README.md file (on the master
branch).
To see the image on GitHub, I have to link to:
/../assets/screenshot.png
or
../assets/screenshot.png
However, this does not work when viewing the README file locally, the image is not displayed (such as when using the Markdown preview feature in VS Code or Atom).
I have even used the git worktree feature, to check out the assets branch in the assets subdirectory:
git worktree add -B assets assets origin/assets
so the directory structure is something like this:
.git
assets
assets/screenshot.png
README.md
This means that, in order to view the image locally in the README file, I have to link to
/assets/screenshot.png
or
assets/screenshot.png
How can I reconcile the two "worlds"?
Is there a way to link to the screenshot so it's always displayed, "whether I view the documentation on GitHub itself, or locally, using a different markup renderer"*?
No, this is not possible and you shouldn't expect it to.
You should make the assets folder a part of your main branch, or you should separate the two into different repositories, or something along those lines.
There is a good reason why GitHub serves this screenshot but that "good reason" is just a technical reason related to how GitHub serves content from your repository.
Let's look at the URL to your screenshot, as used in the served HTML from your main repository page:
https://raw.githubusercontent.com/devliber/ReadmeScreenshotBranch/assets/screenshot.png
As you can see, the name of the branch with the image is part of the URL. Let's try to hack the URL back to your README:
https://raw.githubusercontent.com/devliber/ReadmeScreenshotBranch/master/README.md
If you try this URL you will see that it shows your README file.
So the issue here is that your "hack" to get to the screenshot, from another branch, is that you get this URL:
https://raw.githubusercontent.com/devliber/ReadmeScreenshotBranch/master/../assets/screenshot.png
This resolves to the exact same URL as the first one i posted here and that is why you see the image.
However, if you check out branch X then you shouldn't expect any content from branch Y to be present in your working folder. It "works" on GitHub because of the way they serve content from your branches but it won't, and shouldn't work locally, except if you start checking out multiple branches using worktrees.
这篇关于在GitHub和本地显示存储在不同分支中的GitHub README屏幕截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!