我知道我可以链接到GitHub存储库上文件的特定行号(我相信我以前见过这个)…

我该怎么做呢?


当前回答

用于拉取请求中的一行。

https://github.com/foo/bar/pull/90/files#diff-ce6bf647d5a531e54ef0502c7fe799deR27
https://github.com/foo/bar/pull/
90 <- PR number
/files#diff-
ce6bf647d5a531e54ef0502c7fe799de <- MD5 has of file name from repo root
R <- Which side of the diff to reference (merge-base or head). Can be L or R.
27 <- Line number

只要L和R是正确的,就会得到一条直线。我不确定是否有方法访问L或r,即如果PR增加了一行,你必须使用r。如果它删除了一行,你必须使用L。

从:生成行指针URL到Github拉请求

其他回答

用于拉取请求中的一行。

https://github.com/foo/bar/pull/90/files#diff-ce6bf647d5a531e54ef0502c7fe799deR27
https://github.com/foo/bar/pull/
90 <- PR number
/files#diff-
ce6bf647d5a531e54ef0502c7fe799de <- MD5 has of file name from repo root
R <- Which side of the diff to reference (merge-base or head). Can be L or R.
27 <- Line number

只要L和R是正确的,就会得到一条直线。我不确定是否有方法访问L或r,即如果PR增加了一行,你必须使用r。如果它删除了一行,你必须使用L。

从:生成行指针URL到Github拉请求

有关如何链接到README。md文件的GitHub存储库到特定行数的代码

有三种情况:

We can link to (custom commit) But Link will always link to an old file version, which will not contain new updates in the master branch for example. Example: https://github.com/username/projectname/blob/b8d94367354011a0470f1b73c8f135f095e28dd4/file.txt#L10 We can link to (custom branch) like (master-branch). But the link will always link to the latest file version which will contain new updates. Due to new updates, the link may point to an invalid business line number. Example: https://github.com/username/projectname/blob/master/file.txt#L10 GitHub can not make an auto-link to any file either to (custom commit) nor (master-branch). Because of following business issues: line business meaning, to link to it in the new file length of target highlighted code which can be changed

See:

您可以使用永久链接在问题、pr等中包含代码片段。

引用:

创建到代码段的永久链接

如果您想要获得Markdown代码片段的预览呈现,在复制另一个答案中提到的链接之后,从链接中删除?plain=1参数。

例如,下面将显示一个纯文本链接:

github.com/<organization>/<repository>/blob/<branch_name>/README.md?plain=1#L14

在移除?plain=1参数后,它将显示代码的预览:

github.com/<organization>/<repository>/blob/<branch_name>/README.md#L14

更多信息请参见GitHub文档:创建到代码片段的永久链接。

气息。seib有一个复杂的答案,但我只是想指出,而不是按Y来获得永久链接,GitHub现在有一个非常简单的UI,帮助你实现它。

通过单击行号选择一行或通过按住Shift选择多行(与在文件资源管理器中选择多个文件夹的方式相同): 在选中的第一行的右上角,展开…然后单击“复制永久链接” 就是这样。一个包含选定行和提交散列的链接被复制到你的剪贴板: https://github.com/python/cpython/blob/c82b7f332aff606af6c9c163da75f1e86514125e/Doc/Makefile#L1-L4