34

I did a git commit and pushed to github, but forgot to mention the issue number in the commit (I forgot to write something like ... closes #123).

If I had mentioned the issue number in the commit message, github would have connected the commit to the issue. Is there any way to do this after the commit, when it's too late for me to change the commit message?

EDIT: Assume that it's too late to amend the commit or otherwise alter the history. I am really asking about github functionality, not git.

2
  • Quick, --amend your commit! Just be careful Sep 26, 2013 at 18:48
  • 1
    "If I had mentioned ... git would have connected the commit to the issue". No it wouldn't. git knows nothing of issues or issue tracking systems. github, maybe, but not git...
    – twalberg
    Sep 26, 2013 at 20:41

2 Answers 2

49

In your issue on GitHub, just write a comment with the commit hash. For instance:

Fixed with commit 61d949320fc0bf1a8dba09b3845bddcd153b1a64

GitHub will recognize it as a SHA and link to the right commit page.

1
  • 2
    This worked fine for me. In the specific case the OP asked about (don't want to reset or even do another commit), this should be the accepted answer, IMHO. Feb 11, 2019 at 1:43
10

The Github help page "Can I delete a commit message?" explain how to alter:

  • a commit you just pushed
  • older commits message

But since it changes the history, you need to make anyone having already pulled from the GitHub repo aware of that change.


If rewriting the history isn't possible, you can make a new commit, with a commit message including:

  • the close issue
  • the SHA1 of the previous commit.

GitHub will automatically link that old commit in your new commit message: see for istance the reference to commit cdfd948 in this git commit.

4
  • Thanks, I'm aware of that, but I want to get github to make the connection without having to alter the commit message (because it's too late to do an amend: someone else has pulled, etc.) Sep 27, 2013 at 11:45
  • 2
    @DanHalbert then you can make and push a new commit, with the close message and a reference (in the commit message) to the previous commit. GitHub will link that old commit automatically in the message of the new commit (see for instance the reference to commit cdfd948 in github.com/git/git/commit/2c2b664). I have edited my answer.
    – VonC
    Sep 27, 2013 at 11:53
  • This links the unrelated new commit to an old commit that should have closed the issue. But the issues themselves will be misleadingly linked to this new commit, won't they? It seems like Arthur Clemens' solution is better. Feb 27, 2019 at 5:37
  • 1
    @ButtleButkus Agreed. I supposed I missed that Autolink reference URL feature (help.github.com/en/articles/autolinked-references-and-urls) at the time (sept. 2013), or it was not available.
    – VonC
    Feb 27, 2019 at 17:27

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.