在尝试将存储库镜像到远程服务器时,服务器拒绝树对象4e8f805dd45088219b5662bd3d434eb4c5428ec0.顺便说一句,这不是顶级树,而是子目录.
我怎样才能找出哪个提交间接引用了这个树对象,这样我就可以避免推送链接到这些提交的引用,以便让我所有其余的repo正确推送?
如您所述,您只需要找到所需的提交tree.如果它可能是一个顶级树,你需要一个额外的测试,但因为它不是,你不需要.
你要:
这是微不足道的两个Git"管道"命令加上grep:
#! /bin/sh
#
# set these:
searchfor=4e8f805dd45088219b5662bd3d434eb4c5428ec0
startpoints="master" # branch names or HEAD or whatever
# you can use rev-list limiters too, e.g., origin/master..master
git rev-list $startpoints |
while read commithash; do
if git ls-tree -d -r --full-tree $commithash | grep $searchfor; then
echo " -- found at $commithash"
fi
done
Run Code Online (Sandbox Code Playgroud)
要检查顶级树,您也git cat-file -p $commithash可以查看它是否有哈希值.
请注意,相同的代码将找到blob(假设您从中取出-d选项git ls-tree).但是,没有树可以具有blob的ID,反之亦然.在grep将打印匹配行,所以你会看到,例如:
040000 tree a3a6276bba360af74985afa8d79cfb4dfc33e337 perl/Git/SVN/Memoize
-- found at 3ab228137f980ff72dbdf5064a877d07bec76df9
Run Code Online (Sandbox Code Playgroud)
要清除它以供一般使用,您可能希望git cat-file -t在search-for blob-or-tree上使用它来获取其类型.