我们经常发布文档更新,此页面的翻译可能仍在进行中。有关最新信息,请访问英文文档。如果此页面上的翻译有问题,请告诉我们

Creating a commit with multiple authors

You can attribute a commit to more than one author by adding one or more Co-authored-by trailers to the commit's message. Co-authored commits are visible on GitHub.

本文内容

此文档对您有帮助吗?

帮助我们创建出色的文档!

所有 GitHub 文档都是开源的。看到错误或不清楚的内容了吗?提交拉取请求。

做出贡献

或, 了解如何参与。

Required co-author information

Before you can add a co-author to a commit, you must know the appropriate email to use for each co-author. For the co-author's commit to count as a contribution, you must use the email associated with their GitHub account.

If a person chooses to keep their email address private, you should use their GitHub-provided no-reply email to protect their privacy. Otherwise, the co-author's email will be available to the public in the commit message. If you want to keep your email private, you can choose to use a GitHub-provided no-reply email for Git operations and ask other co-authors to list your no-reply email in commit trailers.

For more information, see "Setting your commit email address."

Tip: You can help a co-author find their preferred email address by sharing this information:

  • To find your GitHub-provided no-reply email, navigate to your email settings page under "Keep my email address private."

  • To find the email you used to configure Git on your computer, run git config user.email on the command line.

Creating co-authored commits using GitHub Desktop

You can use GitHub Desktop to create a commit with a co-author. For more information, see "Write a commit message and push your changes" and GitHub Desktop.

Add a co-author to the commit message

Creating co-authored commits on the command line

  1. Collect the name and email address for each co-author. If a person chooses to keep their email address private, you should use their GitHub-provided no-reply email to protect their privacy.

  2. 输入提交消息以及简短、有意义的更改描述。 在提交描述后,不要加上右引号,而是添加两个空行。

    $ git commit -m "Refactor usability tests.
    >
    >

    提示: 如果您使用文本编辑器在命令行上输入提交消息,请确保在提交描述末尾与 Co-authored-by: 提交尾行之间有两个换行符。

  3. On the next line of the commit message, type Co-authored-by: name <name@example.com> with specific information for each co-author. After the co-author information, add a closing quotation mark.

    If you're adding multiple co-authors, give each co-author their own line and Co-authored-by: commit trailer.

    $ git commit -m "Refactor usability tests.
    >
    >
    Co-authored-by: name <name@example.com>
    Co-authored-by: another-name <another-name@example.com>"

The new commit and message will appear on GitHub the next time you push. For more information, see "Pushing changes to a remote repository."

Creating co-authored commits on GitHub

After you've made changes in a file using the web editor on GitHub, you can create a co-authored commit by adding a Co-authored-by: trailer to the commit's message.

  1. Collect the name and email address for each co-author. If a person chooses to keep their email address private, you should use their GitHub-provided no-reply email to protect their privacy.

  2. After making your changes together, at the bottom of the page, type a short, meaningful commit message that describes the changes you made.

    Commit message for your change

  3. In the text box below your commit message, add Co-authored-by: name <name@example.com> with specific information for each co-author. If you're adding multiple co-authors, give each co-author their own line and Co-authored-by: commit trailer.

    Commit message co-author trailer example in second commit message text box

  4. Click Commit changes or Propose changes.

The new commit and message will appear on GitHub.

Further reading

此文档对您有帮助吗?

帮助我们创建出色的文档!

所有 GitHub 文档都是开源的。看到错误或不清楚的内容了吗?提交拉取请求。

做出贡献

或, 了解如何参与。