Search code examples
githubgithub-flavored-markdown

How to make a short link to specific code line from markdown in github issue text?


How to make a short link to specific code line from markdown in github issue text?

I have read the question How to link to specific line number on github, but it's about putting full link in markdown.

My question is about some markdown shortcut, like @user or #11 issue

Doc Autolinked references and URLs doesn't help.


Solution

  • There is no way to do this.

    When you use @user to point a user page or #17 for a specific issue in the current project, you create a link to a unique object. When you want to provide a link to a file code, maybe you want to point to the latest revision in master (ex: https://github.com/google/apitools/blob/master/apitools/init.py) or on another branch (ex: https://github.com/google/apitools/blob/csl-patch/apitools/init.py). As far as I know, there is no shortcut available in GitHub flavord markdown for linking to a specific file in the project.

    As you already noticed, using this long form (the full URL), you will be able to add a #LXXX to the end of the URL to point to specific line in the file (ex: https://github.com/google/apitools/blob/master/apitools/init.py#L5 or https://github.com/google/apitools/blob/csl-patch/apitools/init.py#L8. But if you really want to avoid long links, you could use GitHub URL Shortener to convert any link (with or without line number) to an equivalent short form: https://git.io/vMD6U