Is it somehow possible to automatically have a link to GitHub issue number in the git commit
message?
8 Answers
Just include #xxx
in your commit message to reference an issue without closing it.
With new GitHub issues 2.0 you can use these synonyms to reference an issue and close it (in your commit message):
fix #xxx
fixes #xxx
fixed #xxx
close #xxx
closes #xxx
closed #xxx
resolve #xxx
resolves #xxx
resolved #xxx
You can also substitute #xxx
with gh-xxx
.
Referencing and closing issues across repos also works:
fixes user/repo#xxx
Check out the documentation available in their Help section.
-
5
Fix issue #xxx
doesn't work for me, any ideas? It references the issue, but doesn't close it.– DennisMay 7, 2012 at 4:55 -
26@Dennis remove the word "issue"– user879121May 9, 2012 at 16:31
-
1@JamesTomasino that's possible - I've noticed that this hasn't been working for me when I'm working on a branch called
dev
. Jan 25, 2013 at 13:56 -
13i'm not going to be the person who moves this answer from 666 votes to 667, but this was VERY helpful. Sep 5, 2016 at 22:06
-
3Worked for me. The only thing I can say about this is when I see xxx, I assume it is a 3 digit number, but obviously
fixes #9
for instance will work. It would be nice if the answer makes this explicitly clear that it is for any length number and you do not need to pad with zeros. Jan 15, 2019 at 17:54
If you want to link to a GitHub issue and close the issue, you can provide the following lines in your Git commit message:
Closes #1.
Closes GH-1.
Closes gh-1.
(Any of the three will work.) Note that this will link to the issue and also close it. You can find out more in this blog post (start watching the embedded video at about 1:40).
I'm not sure if a similar syntax will simply link to an issue without closing it.
-
48You can just use the number of the issue (for example #456) it will link to the task without closing it. Apr 10, 2011 at 14:39
-
12I would choose "gh-1" over "#1" simply because you never know if the repository gets exported/mirrored to somewhere other than github. Then, the "#1" won't make much sense.– huyzJun 6, 2011 at 16:06
-
2@mipadi: is the
.
after "Closes GH-1` necessary? Also, is it case-sensitive? Aug 1, 2011 at 9:56 -
1@Lekensteyn: I don't believe the period is necessary. Not sure about case-sensitivity.– mipadiJan 13, 2012 at 17:21
-
message (closes GH-28)
works for me, not sure if everything is case-insensitive. Jan 13, 2012 at 18:22
github adds a reference to the commit if it contains #issuenbr (discovered this by chance).
You can also cross reference repos:
githubuser/repository#xxx
xxx being the issue number
they have an nice write up about the new issues 2.0 on their blog https://github.blog/2011-04-09-issues-2-0-the-next-generation/
synonyms include
- fixes #xxx
- fixed #xxx
- fix #xxx
- closes #xxx
- close #xxx
- closed #xxx
using any of the keywords in a commit message will make your commit either mentioned or close an issue.
In order to link the issue number to your commit message, you should add:
#issue_number
in your git commit message.
Example Commit Message from Udacity Git Commit Message Style Guide
feat: Summarize changes in around 50 characters or less
More detailed explanatory text, if necessary. Wrap it to about 72
characters or so. In some contexts, the first line is treated as the
subject of the commit and the rest of the text as the body. The
blank line separating the summary from the body is critical (unless
you omit the body entirely); various tools like `log`, `shortlog`
and `rebase` can get confused if you run the two together.
Explain the problem that this commit is solving. Focus on why you
are making this change as opposed to how (the code explains that).
Are there side effects or other unintuitive consequenses of this
change? Here's the place to explain them.
Further paragraphs come after blank lines.
- Bullet points are okay, too
- Typically a hyphen or asterisk is used for the bullet, preceded
by a single space, with blank lines in between, but conventions
vary here
If you use an issue tracker, put references to them at the bottom,
like this:
Resolves: #123
See also: #456, #789
You can also reference the repositories:
githubuser/repository#issue_number
-
It makes no sense (and actually annoys me) that they use "feat" as an abbreviation for "feature", especially when at the same time they use "refactor" which is even longer than "feature". Jul 18, 2017 at 7:01
-
@MichelJung you could argue that
feat
is used more often thanrefactor
, also there's no obvious abbreviation forrefactor
(ref
could mean reference,rf
is too unclear, etc.). Jun 6, 2018 at 16:21
Just as addition to the other answers: If you don't even want to write the commit message with the issue number and happen to use Eclipse for development, then you can install the eGit and Mylyn plugins as well as the GitHub connector for Mylyn. Eclipse can then automatically track which issue you are working on and automatically fill the commit message, including the issue number as shown in all the other answers.
For more details about that setup see http://wiki.eclipse.org/EGit/GitHub/UserGuide
One of my first projects as a programmer was a gem called stagecoach that (among other things) allowed the automatic adding of a github issue number to every commit message on a branch, which is a part of the question that hasn't really been answered.
Essentially when creating a branch you'd use a custom command (something like stagecoach -b <branch_name> -g <issue_number>
), and the issue number would then be assigned to that branch in a yml file. There was then a commit hook that appended the issue number to the commit message automatically.
I wouldn't recommend it for production use as at the time I'd only been programming for a few months and I no longer maintain it, but it may be of interest to somebody.
-
I think your answer is trying to address the exact question from the OP, i.e. "a way to automatically have a link to the issue added in the commit". All other answers rely on programmer remembering to add "Fixes #..., Resolved #... etc." phrase to the commit and this is not going to happen each time as we know it. Upvoting.– demisxApr 11, 2016 at 18:22