gpt4 book ai didi

git - 可以将其他数据放入 git commit 对象吗?

转载 作者:太空狗 更新时间:2023-10-29 13:01:11 24 4
gpt4 key购买 nike

在每个关于 git 对象的教程站点上,我都会看到一个示例,其中 git cat-file 显示提交对象本身的样子,通常如下所示:

tree 552acd444696ccb1c3afe68a55ae8b20ece2b0e6
parent 6a1d380780a83ef5f49523777c5e8d801b7b9ba2
author John Doe <john.doe@exampler.com> 1326496982 -0600
committer John Doe <john.doe@exampler.com> 1326496982 -0600

Some commit message here.

如果顶部有额外的(单行)数据字段,这会混淆 git 工具吗?我假设即使没有,这些字段也不会出现在 git 日志中。

如果它可以有额外的字段,哪个 git 管道命令可以让你创建它? git commit-tree 似乎不那么灵活。

最佳答案

将数据附加到提交的传统方式是“预告片”:提交消息末尾的特殊格式行。 Signed-of-bygit commit -s 添加的行 (docu)就是这样的预告片。

Git 对这些有一些直接支持:

  • git interpret-trailers (docu)是添加或解析这些行的助手
  • git log 有一个格式占位符 %(trailers[:options]) (docu)
  • git for-each-ref 还有一个 %(trailers) 占位符 (docu)

预告片与 git notes 有一些不同:

  • 预告片是提交消息的一部分,因此包含在散列中。因此它们是不可变的。 git notes 是提交(或其他东西)的附加组件。
  • 预告片数据被克隆并推送到远程存储库或从远程存储库推送。 git notes 默认情况下不是。
  • Trailer 数据通过 git cherry-pickgit rebase 和其他工具移动。 git notes ... 有时。

关于git - 可以将其他数据放入 git commit 对象吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20099671/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com