67

Is it possible to make a reference to an issue in Gitlab from a commit message? I haven't found anything on the web.

2 Answers 2

109

There should be a way to reference a GitLab issue from a commit message, simply with #xx (id of the issue).
Consider "Default closing pattern value "

For example the following commit message:

Awesome commit message

Fix #20, Fixes #21 and Closes group/otherproject#22.
This commit is also related to #17 and fixes #18, #19
and https://gitlab.example.com/group/otherproject/issues/23.

will close #18, #19, #20, and #21 in the project this commit is pushed to, as well as #22 and #23 in group/otherproject.

#17 won't be closed as it does not match the pattern.

It works with multi-line commit messages as well as one-liners when used with git commit -m.

See also "Tutorial: It's all connected in GitLab"

Add references in issue or merge request descriptions or in comments.
This will update the issue with info about anything related.

  • To reference an issue: #123
  • To reference a MR: !123
  • To reference a snippet $123

pierreb adds in the comments:

Although this is not specifically asked in the original question, it may be worth adding that one can also cross-reference a previous commit in a new commit message in Gitlab.
You do it by copying the hash from the commit message you want to reference and simply pasting it in the new commit message.
Something along these lines:

This is related with commit 7as7b101

You can see (much) more in:

andrybak adds in the comments:

"You do it by copying the hash from the commit message you want to reference and simply pasting it in the new commit message."

There is also a special, more human-readable format:

git log -1 --format=reference

<abbrev-hash> (<title-line>, <short-author-date>)

See git log PRETTY FORMATS

This format is used to refer to another commit in a commit message and is the same as --pretty='format:%C(auto)%h (%s, %ad)'.
By default, the date is formatted with --date=short unless another --date option is explicitly specified.
As with any format: with format placeholders, its output is not affected by other options like --decorate and --walk-reflogs.


Fr0zenFyr adds in the comments:

Similarly, even a closed issue can be referenced like Related to #78 and #93.

Sign up to request clarification or add additional context in comments.

8 Comments

Although this is not specifically asked in the original question, it may be worth adding that one can also cross-reference a previous commit in a new commit message in Gitlab. You do it by copying the hash from the commit message you want to reference (first eight characters are enough) and simply pasting it in the new commit message. Something along these lines: This is related with commit 7as7b101.
@pierreb Thank you. I have included your comment in the answer for more visibility.
Similarly, even a closed issue can be referenced like Related to #78 and #93
@Fr0zenFyr Thank you. I have included your comment in the answer for more visibility.
@phreed Example: git commit -m "Awesome commit message (Fixes #21 and Closes group/otherproject#22)" (which is in my answer): syntax is group/otherproject#xx, replace group/otherproject by the one of your "different repository".
|
1

for the beginning of commit messages, it needs to be GL-xxx

https://docs.gitlab.com/ee/user/project/issues/crosslinking_issues.html#from-commit-messages

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.