gpt4 book ai didi

git - git commit 和 git commit-tree 有什么区别

转载 作者:太空狗 更新时间:2023-10-29 13:14:33 31 4
gpt4 key购买 nike

我正在阅读有关 git 对象的信息:blob、树、提交、标签。为了更好地理解 git 的工作原理,我尝试了一些低级命令,如 write-treecommit-tree

  1. mkdir 测试; cd 测试 --> git init
  2. 我创建了一个文件并git add file。我可以看到在 .git/objects
  3. 中生成了一个 blob 和树对象
  4. git write-tree 打印当前树ID
  5. git commit-tree treeID -m "commit a tree" 提交这棵树。在这个操作之后,生成了一个提交对象,我可以看到它确实包含作者、日期等。但是,我无法使用 git log 检查我的提交,错误是:fatal : 错误的默认修订版“HEAD”

完成上述操作后,当我运行 git status 时,我看到文件仍在索引中等待提交。 commit-tree 有什么用,commit-tree 和 `commit' 有什么区别?

最佳答案

git-commit - 记录对存储库的更改

在新提交中存储索引的当前内容以及来自用户的描述更改的日志消息。

git commit "records changes to the repository"

显示了 git-commit 的图示 here在 SO

git-commit-tree - 创建一个新的提交对象

根据提供的树对象创建一个新的提交对象,并在 stdout 上发出新的提交对象 id。

This is usually not what an end user wants to run directly. Creates a new commit object based on the provided tree object and emits the new commit object id on stdout. The log message is read from the standard input, unless -m or -F options are given.

关于git - git commit 和 git commit-tree 有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29623837/

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