使用 git hash-object 构建 git commit 对象?

use*_*590 5 git

如何使用 git hash-object 手动构建 git commit 对象?我现在它与 blob 一起工作,它的文档说它可以通过使用 -t 来构建不同的对象,但是你如何构建一个提交呢?

Ari*_*ini 4

这是一个完整且有效的脚本示例,该脚本commit无需运行即可创建对象git commit

mkdir project
cd project
git init

hash=`echo -n "" | git hash-object -w --stdin`

tree=`echo -e "100644 blob ${hash}\temptyfile" | git mktree`

commit=`echo -e "yourname\nyour@email.com\n2013 12:20:15 +0200\ncommittername\ncommitter@email.com\n2013 10:13:15 +0200" | git commit-tree ${tree}`

git update-ref refs/heads/master ${commit}
Run Code Online (Sandbox Code Playgroud)

要验证脚本是否创建了包含空文件的提交,请运行:

git checkout --
git log --oneline
#2abbdc2 yourname your@email.com 2013 12:20:15 +0200 committername committer@email.com
Run Code Online (Sandbox Code Playgroud)

编辑:修复和改进