Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Github - link to function in source

I know I can have anchors to a certain line, but if the source changes that line might become irrelevant. Example:

...source.php#L33 < line 33 may become line 40 later :(

Is there some way to tell GitHub to link to a certain function or property from the source, without specifying the line?

(The source is written in PHP code.)

like image 964
Alex Avatar asked Aug 13 '13 23:08

Alex


People also ask

How do I link to a specific line in GitHub?

You can link to a specific line in the Markdown file the same way you can in code. Append #L with the line number or numbers at the end of the url. For example, github.com/<organization>/<repository>/blob/<branch_name>/README.md?

How do I reference code on GitHub?

Include the title of the program or source code and identify the type. Type the title of the program from the ReadMe file. Copy the capitalization used by the authors to identify the code, since it may have significance. Use the description "Source code" for a GitHub repository, enclosed in square brackets.

How do I reference a GitHub issue?

You can reference issues between repositories by mentioning user/repository#number in an issue. Once we see something like that — say, github/enterprise#59 — we'll make sure to update issue #59 in github's enterprise repository and let you know where it was referenced from.


2 Answers

AFAIK, no, but you can link to a certain revision of the file, and thus, you can know for sure that line will always point at the start of the function.

The URL looks like /{user}/{repo}/blob/{hash}/{file}#L{line}

To get it, click "Commits", select the last commit, click "Browse code", and find your file and line as usual.

documentation

like image 152
boen_robot Avatar answered Oct 17 '22 07:10

boen_robot


Yes you can. Newer browsers support highlighting a portion of text and scrolling to it.

Example: common.c#:~:text=static%20ssize_t%20led_current_store

All you have to do is to add this to the end of your URL:

#:~:text=function_name

Some browsers do not support this, though: https://caniuse.com/url-scroll-to-text-fragment

Enjoy!

like image 45
kolypto Avatar answered Oct 17 '22 06:10

kolypto