我正在阅读有关 git 对象的信息:blob、树、提交、标签。为了更好地理解 git 的工作原理,我尝试了一些低级命令,如 write-tree
和 commit-tree
。
mkdir 测试; cd 测试
-->git init
- 我创建了一个文件并
git add file
。我可以看到在.git/objects
中生成了一个 blob 和树对象
git write-tree
打印当前树IDgit 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/