gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 14:00:55 24 4
gpt4 key购买 nike

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

最佳答案

这是一个完整且有效的脚本示例,它创建了一个 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}

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

git checkout --
git log --oneline
#2abbdc2 yourname your@email.com 2013 12:20:15 +0200 committername committer@email.com

编辑:修复和改进

关于git - 使用 git hash-object 构建 git commit 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16064968/

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