How to provide a hyperlink to a particular line(s) of code in stash / bitbucket?

Upon prompting, you will be presented with the following question: Here is a description of each available option: stage this hunk for the next commit, do not stage this hunk for the next commit, quit and do not stage this hunk or any remaining hunks, stage this hunk and all subsequent hunks in the file, do not stage this hunk or any later hunks in the file, select a hunk to go to or search for a hunk matching the given regex, leave this hunk undecided and proceed to the next undecided hunk, leave this hunk undecided and proceed to the next hunk, leave this hunk undecided and go back to the previous undecided hunk, leave this hunk undecided and go back to the previous hunk, split the current hunk into smaller hunks, manually edit the current hunk. Additionally, if the file is not yet in the repository, you can perform the necessary actions beforehand.

Question:

By utilizing GitHub, we have the ability to employ URLs that are structured in the following manner.

www.github.com/username/repo/filename.c#L20-L45

Please take note of the

#L20-L45

located at the end, indicating the lines of code from the 20th to the 45th that are highlighted when the page is loaded in the browser.

Is there a way to link to specific lines of code in
stash / bitbucket
? It seems that this convention does not function in the same manner.
“””.


Solution 1:

Within BitBucket, it is necessary for a URL to conclude with

#lines-x:y

.

Example:

Please refer to the following link for the code snippet: https://bitbucket.org/stangenberg/docker-docker/src/1ac537b84855db2cc5ee0caf31c782900e094d8e/docker.sh#lines-13:15.

Concerning Stash, which is now renamed BitBucket Server in 2019+, it is expected that Stash 3.8 in 2015 will have the capability to support deep linking with
multiline selection
. This information is documented in issue BSERV-2477.

By utilizing shift+click, developers have the ability to choose a sequence of lines, subsequently incorporating additional lines into the selection via command+click (or control+click). Afterward, they can copy the URL and share their selection with fellow developers.

https://info.seibert-media.net/download/attachments/11113140/Stash-38.png?version=1&modificationDate=1474904524000&api=v2

The OP confirms in the comments:

The generated stash URL follows a specific format, with

#13-15

at its end.

You can find the relevant code snippet at this link: https://bitbucket.org/stangenberg/docker-docker/src/1ac537b84855db2cc5ee0caf31c782900e094d8e/docker.sh#13-15.

As cellepo notes in the comments:

  • It is not possible to do this in a
    pull request
    /code-review page (

    https://bitbucket.../pull-requests/...

    ),
    however
    “””.
  • The action can be performed on a source page, such as the example URL mentioned earlier.


Solution 2:


It seems possible that the url lines ending may vary depending on different
Bitbucket version
syntax.

The answer provided by VonC is satisfactory. It seemed to have resolved my issue in the past, but it is no longer effective for me. I suspect that the problem may be due to a different version of BitBucket.

If @VonC’s answer does not solve the problem for you, you can attempt an alternative solution by focusing on

#7-8

.

bitbucket.your.domain/.../your/project/structure/.../yourfile.filetype#7-8

The UI rendering of that differs slightly from the linked example by @VonC, as it only displays blue highlighting on the line-number gutter instead of code identifier
yellow highlighting
.

“Rephrased MSDTHOT”:

The rendering appears to be the same as the one by @VonC for [non-contiguous] multiline selection. In my version of Bitbucket, non-contiguous selection with CMD + click also functions similarly (as shown below – with emphasis on

,10,12

).

bitbucket.your.domain/.../your/project/structure/.../yourfile.filetype#7-8,10,12


Solution 3:


In order to configure
highlighting multiple
blocks in BitBucket, it is necessary for the URL to have the ending of

#lines-a:b,c:d, ...

.

To avoid repetition, consider removing

%20

if it pertains to whitespace within the URL.

Frequently Asked Questions

Posted in Uncategorized