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

标签 git commit

我正在阅读有关 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/

相关文章:

git - 推送到 GitHub 的 Node.js 模块

github)从 merge 中删除提交

git - 如何将本地提交组组合到 IDEA 中的单次推送?

Git:别名错误:使用 '--' 将路径与修订分开

ios - 如何连接 Xcode 9 和 GitHub?

commit - 有没有办法避免在 RTC 上提交变更集?

git - 如果有未跟踪的文件,如何禁止 git commit?

Git 别名 : append string to commit message

git - 如果 HEAD 分离,如何将提交移到 master 之上?

git - 使用 git 在 Visual Studio 2015 中提交之间的差异