164

I know you can close issues by putting closes #1 or fixes #1 in the commit message. What is the best way to close multiple issues in the same commit message?

Also, it appears that using fixes rather than closes doesn't create a link from the commit message to the issue, but it does close the issue. What's up with that?

Esoteric Screen Name
  • 6,082
  • 4
  • 29
  • 38
Rayne
  • 31,473
  • 17
  • 86
  • 101

5 Answers5

223

Closes #1, closes #2, closes #3; rest of commit message.

The closes clauses can be anywhere in the message and fixes is a valid synonym:

This fixes a memory leak in foo() that closes #4,
also fixes #5 which is a duplicate.

The following used to work, but nowadays only references issues #2 and #3.

Closes #1, #2, #3

Jakob Borg
  • 23,685
  • 6
  • 47
  • 47
  • 2
    This doesn't seem to work for me, it only closes the first item in the list and not the others. Has the syntax changed since this post? I've Googled it, but there doesn't seem to be a whole lot of help out there about this. – Mark Bell Jan 31 '11 at 18:32
  • 1
    Agreed. Fixes #1, #2 works to reference both... but only closes #1. – waldo Apr 30 '11 at 21:41
  • @waldo I think this worked when I wrote it -- nowadays then, how about `Closes #1, closes #2, closes #3`? Verbose and redundant, yes, but maybe it works? – Jakob Borg May 01 '11 at 19:28
  • Yup, "Fixes #1 - Fixes #2 - actual commit message." works and makes some sense (if verbose) - i.e. I clearly close and refer (without closing) multiple different issues from a single commit message. – waldo May 20 '11 at 15:14
  • 1
    You don't have to put the closes/fixes part of the message anywhere specific in the commit message. For example, "refactored class foo, fixes #3, new feature bar, closes #8, don't break backwards compatibility" should close #3 and #8. Still have this 'reference only' issue as of March 2012.. – Casey Kuball Mar 09 '12 at 18:15
  • 7
    Any idea why they changed the behaviour of `Closes #1, #2, #3`? I find it ridiculous to write 10 `closes` plus the numbers of the issues that are to be close instead of a single close and all the numbers after that. :-/ – rbaleksandar Oct 07 '15 at 16:31
  • Just a small side-note: I have issues doing that in **GitLab** but not in **GitHub** so it also depends on whether the API of the git-based VC platform supports it or not. – rbaleksandar Oct 28 '15 at 16:19
  • 1
    @Darthfelt That's a little off, because they have to be together. For example, `This closes issue #3` will only reference `#3`. It doesn't matter where `closes #3` or `fixes #3` etc is at in the commit message, but it has to be joint. – Hobbyist Mar 02 '17 at 06:10
  • I just used "Fixes #1 and fixes #2", both issues did NOT close – Cecile Jul 30 '17 at 15:30
50

The answer and a comment to that answer mention the following format:

Closes #1, closes #2, closes #3; Actual commit message

If I had a project worth participating in and someone sent a pull request with such commit messages, I would refuse the pull no matter how beautiful the code was.

It is possible this is just a matter of my personal preference and will end up beaten to the very ground by people used to compact commit messages that clutter up Git history summaries, but I would much rather see commit messages with the format:

Summary of the change made.

Fixed following bugs:
* Modified error loader, fixes #1
* Returned a nonstale pointer, fixes #2
* Applied new graphics to gui elements, closes #3

He asked for the best way to close multiple issues.

Also note that if you push the commit with the message to any other branch than the current default branch of your repository, the issues will only be referenced. Pushing the commit to the main branch will close the issues. See: Link to GitHub issue number not working?

Community
  • 1
  • 1
JNissi
  • 1,120
  • 9
  • 22
15

Note that, since January 2013, "Closing Issues via Commit Messages" has changed:

Now when you enter "Fixes #33" in a commit message, issue 33 will only be closed once the commit is merged into your default branch (usually master).

This is super useful because it means the issue's open / closed status will map to your default branch.
If the bug isn't fixed in your default branch, the issue will remain open.
Once the commit with the fix is merged into your default branch the issue will be automatically closed.

You can use any of these keywords to close an issue via commit message:

close, closes, closed, fixes, fixed

As illustrated by the question "Closing a GitHub Issue while on a different branch", this causes some confusion at first.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
9

Here from Github self a documentation: Linking a pull request to an issue

Resolves #10, resolves #123, resolves octo-org/octo-repo#100

Screenshot from GitHub Documentation

No Name Pro
  • 160
  • 1
  • 7
6

"Closing issues using keywords" is a document from GitHub that describes how to close issues, tags and how to close multiple issues.

To answer your questions the answer from GitHub is:

Closing multiple issues

To close multiple issues, preface each issue reference with one of the above keywords. You must use the keyword before each issue you reference for the keyword to work.

For example, This closes #34, closes #23, and closes example_user/example_repo#42 would close issues #34 and #23 in the same repository, and issue #42 in the "example_user/example_repo" repository.

Community
  • 1
  • 1
Vlad Bezden
  • 83,883
  • 25
  • 248
  • 179