簡體   English   中英

如何在子模塊中搜索 Git 提交?

[英]How to search for a Git commit in submodules?

我有一個包含多個子模塊的倉庫。 我有一個提交的 hash 但不知道它屬於哪個子模塊,我怎么能找到它的確切子模塊?

git submodule status將為您提供每個子模塊當前簽出提交 hash id 的列表。 您可以對其進行解析並找出與提交 hash 對應的子模塊的名稱:

$ commit_id="14f4e19f1c"
$ git submodule status | awk -v commit_id="$commit_id" '$0 ~ commit_id {print $2}'

(這假設您正在使用來自該子模塊的最新提交 hash)

在所有子模塊中遞歸運行git show 隱藏錯誤信息,忽略錯誤; 找到 hash 時報告子模塊( git show不返回錯誤):

git submodule foreach -q --recursive 'git show -q $hash 2>/dev/null && echo $name || :'

請參閱文檔

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM