如何找到指向git树对象的提交? [英] How to find the commit(s) that point to a git tree object?

查看:67
本文介绍了如何找到指向git树对象的提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试将存储库镜像到远程服务器时,服务器拒绝了树对象4e8f805dd45088219b5662bd3d434eb4c5428ec0.顺便说一下,这不是顶级树,而是子目录.

In trying to mirror a repo to a remote server, the server is rejecting tree object 4e8f805dd45088219b5662bd3d434eb4c5428ec0. This is not a top-level tree, by the way but a subdirectory.

我该如何找出哪些提交间接引用了该树对象,因此可以避免推送链接到那些提交的引用,以使我的所有其他回购协议得以正确推送?

How can I find out which commit(s) indirectly reference that tree object so I can avoid pushing the refs that link to those commits in order to get all the rest of my repo to push properly?

推荐答案

如您所述,您只需要查找具有所需tree的提交即可.如果它可能是顶级树,则需要进行额外的测试,但由于不是,您不需要进行测试.

As you noted, you just need to find the commit(s) with the desired tree. If it could be a top level tree you would need one extra test, but since it's not, you don't.

您想要:

  • 用于某些提交(例如,所有可从给定分支名称访问的那些提交)
  • 如果该提交具有作为子树的目标树哈希:打印提交ID

与两个Git"plumbing"命令加grep无关紧要:

which is trivial with two Git "plumbing" commands plus 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

要检查顶级树,您也将git cat-file -p $commithash并查看其中是否包含哈希.

To check top-level trees you would git cat-file -p $commithash as well and see if it has the hash in it.

请注意,相同的代码将找到blob(假设您从git ls-tree中删除了-d选项).但是,没有树可以具有Blob的ID,反之亦然. grep将打印匹配的行,以便您看到例如:

Note that this same code will find blobs (assuming you take out the -d option from git ls-tree). However, no tree can have the ID of a blob, or vice versa. The grep will print the matching line so you'll see, e.g.:

040000 tree a3a6276bba360af74985afa8d79cfb4dfc33e337    perl/Git/SVN/Memoize
 -- found at 3ab228137f980ff72dbdf5064a877d07bec76df9

要清理此代码以备一般使用,您可能需要在搜索blob-or-tree上使用git cat-file -t来获取其类型.

To clean this up for general use, you might want to use git cat-file -t on the search-for blob-or-tree to get its type.

这篇关于如何找到指向git树对象的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆