32

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.

Dan Halbert
  • 2,761
  • 3
  • 25
  • 28
  • Quick, `--amend` your commit! Just [be careful](http://stackoverflow.com/questions/448919/how-can-i-remove-a-commit-on-github?rq=1) – Wayne Werner Sep 26 '13 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 '13 at 20:41

2 Answers2

42

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.

Buttle Butkus
  • 9,206
  • 13
  • 79
  • 120
Arthur Clemens
  • 2,848
  • 24
  • 18
  • 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. – SvenAelterman Feb 11 '19 at 01:43
9

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.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 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.) – Dan Halbert Sep 27 '13 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 https://github.com/git/git/commit/2c2b664). I have edited my answer. – VonC Sep 27 '13 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. – Buttle Butkus Feb 27 '19 at 05:37
  • 1
    @ButtleButkus Agreed. I supposed I missed that Autolink reference URL feature (https://help.github.com/en/articles/autolinked-references-and-urls) at the time (sept. 2013), or it was not available. – VonC Feb 27 '19 at 17:27