本文介绍了如何通过子模块的SHA查找提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有子模块的仓库.对于给定的子模块SHA,我想在存在该子模块并具有给定SHA的存储库中查找提交.

I have a repo which has a submodule. For a given SHA of the submodule, I want to find commits in the repo where this submodule exists and has the given SHA.

我该如何使用最新版本的git?

How would I do this with the most recent version of git?

推荐答案

您可以使用 git ls-tree 读取 gitlink (a )以读取子模块的SHA1:

You can use git ls-tree to read that gitlink (a special entry in the index) to read the SHA1 of a submodule:

git ls-tree HEAD mysubmodule
160000 commit c0f065504bb0e8cfa2b107e975bb9dc5a34b0398  mysubmodule

这将包括在子存储库中记录子模块的SHA1.

That will include the SHA1 at which the submodule is recorded in the parent repo.

知道,您可以将其与 git filter-branch 结合使用,使用索引过滤器(以避免每次提交都必须签出父仓库)

Knowing that, you can combine it with a git filter-branch, using an index filter (to avoid having to checkout the parent repo for each commit)

git filter-branch --prune-empty --index-filter 'git ls-tree mysubmodule' -- --all|grep <yourSHA1>

结合 git rev-list git ls-tree 可能更干净:

A shell approach combining git rev-list and git ls-tree is probably cleaner:

#!/bin/sh
for r in $(git rev-list FIRST_REV..LAST_REV)
do
    git ls-tree $r mysubmodule
done | grep <yourSHA1>

使用 git 2.7,您很快就会得到:

git for-each-ref --contains <SHA1>

那应该更容易.

这篇关于如何通过子模块的SHA查找提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 11:34