git commit中author和commitor的区别

让我们用一个具体的例子来展示 Git 中的作者(author)和提交者(committer)之间的区别,并通过实际的 Git 命令来演示。

假设 Alice 写了一些代码并创建了一个补丁文件,然后 Bob 使用这个补丁文件在他的 Git 仓库中创建了一个提交。在这个场景中,Alice 是作者,而 Bob 是提交者。

Alice 创建补丁文件

  1. Alice 在她的本地仓库中编写了代码并提交:
echo "print('Hello, world!')" > hello.py
git add hello.py
git commit -m "Add hello script"
  1. 然后,Alice 使用 git format-patch 创建补丁文件:
git format-patch -1 HEAD

这将创建一个补丁文件,例如 0001-Add-hello-script.patch

Bob 应用补丁文件

  1. Bob 收到了 Alice 的补丁文件,并将其应用到他自己的仓库中:
git apply 0001-Add-hello-script.patch
  1. Bob 使用 git commit 创建提交,同时保留 Alice 作为作者:
git commit --author="Alice <alice@example.com>" -m "Add hello script from Alice"
  1. Bob 将这些更改推送到远程仓库:
git push origin master

检查提交信息

Bob 可以使用 git log 查看提交信息,以确认作者和提交者的信息:

git log --format=fuller

输出可能如下:

commit ead4a5f7f8c6b0d4d9f2a9b8b1c6e8d2d9f3a1c4
Author:     Alice <alice@example.com>
AuthorDate: Mon May 19 14:22:34 2024 +0000
Commit:     Bob <bob@example.com>
CommitDate: Mon May 19 15:45:56 2024 +0000

    Add hello script from Alice

在这个例子中:

  • Author(作者):Alice,表明是谁编写了这段代码。
  • Committer(提交者):Bob,表明是谁在仓库中创建了这个提交。

通过这种方式,Git 记录了谁是实际编写代码的人(Alice),以及谁将其提交到仓库中的人(Bob),从而区分了作者和提交者。

  • 10
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值