Git中作者和提交者有什么区别?

52

4
实际上,您会注意到一个是作者,另一个是提交者。 - Chris Eberle
1
可能是 Git 中作者和提交者的区别是什么? 的重复问题。 - Anshul Goyal
5个回答

64

那不是两个作者,而是一个作者和一个提交者。这两个字段有不同的含义。作者是创建内容的人,提交者是提交了内容的人。当您进行普通提交时,您既是作者又是提交者(并且两者都带有相关的电子邮件和时间戳)。

但它们可以在一些关键方面变得不同:

  • git format-patch / git am - 这对命令允许您将提交转换为补丁,通常通过电子邮件提交,然后由其他人应用。您仍然是作者; 应用它们的人是提交者。这几乎肯定是在github上发生的情况。

  • git commit --amendgit rebasegit filter-branch - 这些都是基本上是历史重写的变体,范围从单个提交到一些分支历史记录到整个历史记录。它们可以潜在地修改提交者信息 - 特别是,它们总是重写提交者的时间戳。原始作者仍然保持不变(在默认操作模式下),如果作者也是进行重写的人,则他们的名称和电子邮件地址保持不变,但时间戳自然会改变。


1
为了精确地重写历史记录,人们可以修改一切--包括作者信息。虽然很少在实践中使用,但仍然有可能。 - Ivan Danilov
@Chirantan:所以这里基本上所有其他的Git手册链接都是因为kernel.org崩溃了,而且还没有恢复手册。没必要试图重写每一个手册。只需使用man git-format-patch即可。 - Cascabel

7
该提交没有多个作者相关联(目前也不可能将多个作者分配给单个提交)。在这种情况下,gliese1337是作者,而felixge是提交者。很可能是因为gliese1337提交了一个拉取请求,然后由felixhe(存储库所有者)接受并提交的。这种工作流在GitHub上非常常见。这对于项目维护者通过电子邮件接收补丁的情况也很有帮助,这样即使补丁的作者没有访问项目的提交权限,补丁本身的作者仍然可以得到补丁的贡献。

一些相关链接:

关于Git作者归属的简短Git Wiki部分
Git核心中多个作者功能的特性请求


4

这并不是多个作者,一个人是作者,另一个人是提交者。

如果您克隆一份,您就可以清楚地看到:

$ git cat-file -p 0a0b150668daa3c6f016
tree 91edcb411b7cd0708c1f5bb05621846146c9425a
parent 6b9ffe3653fe59f035b01ba1f46b5f2650be00ca
author Logan Kearsley <chronosurfer@gmail.com> 1308937685 -0700
committer Felix Geisendo╠Иrfer <felix@debuggable.com> 1309117893 +0200

Slight but definite & consistent performance boost.

3

类似GitHub和GitLab的Git网络接口

在这种系统中,当合并补丁时,根据存储库设置,作者可能与提交者不同。

由于Git(Hub|Lab)将上游和分叉存储库都放在同一台机器上,因此它可以自动执行您在本地可以执行的任何操作:

  • Create a merge commit.

    Does not generate author != committer.

    Keeps the SHA or the new commit intact, and creates a new commit:

    * Merge commit (committer == author == project maintainer)
    |\
    | * Feature commit (committer == author == contributor)
    |/
    * Old master (random committer and author)
    

    Historically, this was the first available method on GitHub.

    Locally, this is done with git merge --no-ff.

    This produces two commits per pull request, and keeps a fork in the git history.

  • rebase on top of master

    While this is not mandatory in principle, and not even done by default locally by git rebase, GitHub also hacks the commits to set committer == whoever pressed the merge button.

    The reason for doing this, is that it gives accountability to the project maintainer.

    The git tree now looks like:

    * Feature commit (committer == maintainer, author == contributor)
    |
    * Old master (random committer and author)    
    

    which is exactly like that of the git apply email patches.

目前在GitHub上:

  • 您可以通过合并按钮上的下拉菜单选择方法
  • 仓库所有者可以在仓库设置中启用或禁用方法

https://help.github.com/articles/about-merge-methods-on-github/


1
简而言之,当你向托管在github/gitlab等上的repo发起Pull Request并被repo维护者接受时,你是作者,他/她是提交者。
当你克隆这个repo时,使用git cat-file -p xxx_hash命令将显示作者和提交者的消息。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接