【问题标题】:Link to the issue number on GitHub within a commit message在提交消息中链接到 GitHub 上的问题编号
【发布时间】:2010-12-13 19:44:04
【问题描述】:

是否有可能自动git commit 消息中提供指向 GitHub 问题编号的链接?

【问题讨论】:

标签: git github git-commit


【解决方案1】:

只需在您的提交消息中包含 #xxx 即可引用问题而无需关闭它。

有了新的GitHub issues 2.0,你可以使用这些同义词来reference an issue and close它(在你的提交信息中):

  • fix #xxx
  • fixes #xxx
  • fixed #xxx
  • close #xxx
  • closes #xxx
  • closed #xxx
  • resolve #xxx
  • resolves #xxx
  • resolved #xxx

您也可以将#xxx 替换为gh-xxx

引用和closing issues across repos 也可以:

fixes user/repo#xxx

查看“帮助”部分中的the documentation

【讨论】:

  • Fix issue #xxx 对我不起作用,有什么想法吗?它引用了这个问题,但没有关闭它。
  • @Dennis 删除“问题”一词
  • @JamesTomasino 这是可能的 - 我注意到当我在一个名为 dev 的分支上工作时,这对我不起作用。
  • 各用在什么情况下?
  • 我不会成为将这个答案从 666 票变为 667 票的人,但这非常有帮助。
【解决方案2】:

如果您想链接到 GitHub 问题关闭该问题,您可以在 Git 提交消息中提供以下行:

Closes #1.
Closes GH-1.
Closes gh-1.

(这三个中的任何一个都可以。)请注意,这将链接到问题并关闭它。您可以在此blog post 中了解更多信息(大约 1:40 开始观看嵌入视频)。

我不确定类似的语法是否会简单地链接到一个问题而不关闭它。

【讨论】:

  • 您可以只使用问题的编号(例如#456)它将链接到任务而不关闭它。
  • 我会选择“gh-1”而不是“#1”,因为您永远不知道存储库是否被导出/镜像到 github 以外的其他地方。那么,“#1”就没有多大意义了。
  • @mipadi:“关闭 GH-1”之后的 . 是否必要?另外,它是否区分大小写?
  • @Lekensteyn:我不认为这段时间是必要的。不确定是否区分大小写。
  • message (closes GH-28) 对我有用,不确定是否所有内容都不区分大小写。
【解决方案3】:

如果提交包含#issuenbr(偶然发现),github 会添加对提交的引用。

【讨论】:

  • 刚刚测试过,效果很好,谢谢...这是应该标记为正确答案的那个...
  • 这应该是已接受答案的一部分。有时您只是想提及这个问题,但还没有做任何事情。
【解决方案4】:

你也可以交叉引用repos:

githubuser/repository#xxx

xxx 是问题编号

【讨论】:

    【解决方案5】:

    他们在博客上写了一篇关于新问题 2.0 的精彩文章 https://github.blog/2011-04-09-issues-2-0-the-next-generation/

    同义词包括

    • 修复#xxx
    • 固定#xxx
    • 修复#xxx
    • 关闭#xxx
    • 关闭#xxx
    • 关闭#xxx

    在提交消息中使用任何关键字都会使您的提交被提及或关闭问题。

    【讨论】:

    • 那已经在我的列表中了,我认为它们不区分大小写。
    【解决方案6】:

    为了将问题编号链接到您的提交消息,您应该添加: #issue_number 在您的 git 提交消息中。

    示例提交消息来自 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
    

    您也可以参考存储库:

    githubuser/repository#issue_number
    

    【讨论】:

    • 他们使用“feat”作为“feature”的缩写是没有意义的(实际上让我很恼火),尤其是当他们同时使用比“feature”更长的“refactor”时"。
    • @MichelJung 你可能会说featrefactor 更常用,而且refactor 也没有明显的缩写(ref 可能意味着参考,rf 太不清楚了,等)。
    【解决方案7】:

    就像其他答案一样:如果您甚至不想使用问题编号编写提交消息并且碰巧使用 Eclipse 进行开发,那么您可以安装 eGit 和 Mylyn插件以及 Mylyn 的 GitHub 连接器。然后 Eclipse 可以自动跟踪您正在处理的问题并自动填写提交消息,包括所有其他答案中显示的问题编号。

    有关该设置的更多详细信息,请参阅http://wiki.eclipse.org/EGit/GitHub/UserGuide

    【讨论】:

      【解决方案8】:

      作为程序员,我的第一个项目是一个名为 stagecoach 的 gem,它(除其他外)允许自动将 github 问题编号添加到分支上的每个提交消息中,即尚未真正回答的问题的一部分。

      基本上,在创建分支时,您会使用自定义命令(类似于stagecoach -b <branch_name> -g <issue_number>),然后问题编号将在 yml 文件中分配给该分支。然后有一个commit hook 自动将问题编号附加到提交消息中。

      我不建议将它用于生产用途,因为当时我只编程了几个月并且不再维护它,但它可能会引起某些人的兴趣。

      【讨论】:

      • 我认为您的答案是试图解决来自 OP 的确切问题,即“一种自动链接到提交中添加的问题的方法”。所有其他答案都依赖于程序员记住添加“Fixes #..., Resolved #... etc”。提交的短语,正如我们所知,这不会每次都发生。点赞。
      猜你喜欢
      • 1970-01-01
      • 2015-03-09
      • 2011-10-21
      • 1970-01-01
      • 2011-04-02
      • 1970-01-01
      • 2012-12-08
      • 2016-03-12
      • 2012-02-13
      相关资源
      最近更新 更多