简体   繁体   English

查找 git 中的所有子模块及其提交

[英]Find all submodules in git and their commits

I have a project on my git repositary which contains submodules and those submodules contains feather submodules.我的 git 存储库中有一个项目,其中包含子模块,这些子模块包含 feather 子模块。

Since I am not responsible to all the submodules, I don't know what changed there after I updated the commit I was looking at.由于我不对所有子模块负责,所以我不知道在更新我正在查看的提交后那里发生了什么变化。 For this reason I would like to document the current state.出于这个原因,我想记录当前的 state。

This means, I would like to know all the submodules I am using (explicit and non-explicit).这意味着,我想知道我正在使用的所有子模块(显式和非显式)。 For each submodules I would like to know its Tag and\or commit.对于每个子模块,我想知道它的标签和/或提交。

I found:我发现:

git ls-files --stage

helpful, but shows only commits from my repository and not inside the submodules.有帮助,但只显示来自我的存储库的提交,而不是子模块内部的提交。

Any idea?任何的想法?

git submodule foreach --recursive "git describe --tags HEAD --exact-match 2>/dev/null || git rev-parse HEAD"

Recursively in each submodule, run the commands git describe --tags HEAD --exact-match 2>/dev/null || git rev-parse HEAD 在每个子模块中递归运行命令git describe --tags HEAD --exact-match 2>/dev/null || git rev-parse HEAD git describe --tags HEAD --exact-match 2>/dev/null || git rev-parse HEAD

First try to find the most recent tag that exactly points at the head commit of each submodule. 首先,尝试找到恰好指向每个子模块的头提交的最新标签。 If no tag is found, then return the commit. 如果未找到标签,则返回提交。

git ls-files --stage

helpful, but shows only commits from my repository and not inside the submodules.有帮助,但只显示来自我的存储库的提交,而不是子模块内部的提交。

Before Git 2.36 (Q2 2022), many output modes of "ls-files" do not work with its "--recurse-submodules" option, but the "--stage" mode has now been taught to work with it.在 Git 2.36(2022 年第 2 季度)之前,“ls-files”的许多 output 模式无法使用其“--recurse-submodules”选项,但“--stage”模式现在已被教导可以使用它。

See commit 290eada (23 Feb 2022) by Jonathan Tan ( jhowtan ) .请参阅Jonathan Tan ( jhowtan )提交 290eada (2022 年 2 月 23 日)。
(Merged by Junio C Hamano -- gitster -- in commit 7a4e06c , 06 Mar 2022) (由Junio C Hamano 合并gitster 提交 7a4e06c ,2022 年 3 月 6 日)

ls-files : support --recurse-submodules --stage ls-files : 支持--recurse-submodules --stage

Signed-off-by: Jonathan Tan签字人:Jonathan Tan

e77aa33 (" ls-files : optionally recurse into submodules", 2016-10-10, Git v2.11.0-rc0 -- merge listed in batch #11 ) taught ls-files the --recurse-submodules argument, but only in a limited set of circumstances. e77aa33 (“ ls-files :可选地递归到子模块”,2016 年 10 月 10 日,Git v2.11.0-rc0 - 合并列在批次 #11中)教ls-files --recurse-submodules参数,但仅在有限的情况。

In particular, --stage was unsupported, perhaps because there was no repo_find_unique_abbrev() , which was only introduced in 8bb9557 (" sha1 -name.c``: add repo_find_unique_abbrev_r() ", 2019-04-16, Git v2.22.0-rc0 -- merge listed in batch #8 ).特别是, --stage不受支持,可能是因为没有repo_find_unique_abbrev() ,它仅在8bb9557中引入(" sha1 -name.c``: add repo_find_unique_abbrev_r() ", 2019-04-16, Git v2.22.0 -rc0—— 合并第 8 批中列出)。

This function is needed for using --recurse-submodules with --stage.--recurse-submodules与 --stage 一起使用需要这个 function。

git ls-files now includes in its man page : git ls-files现在包含在其手册页中:

--recurse-submodules : --recurse-submodules

Recursively calls ls-files on each active submodule in the repository.在存储库中的每个活动子模块上递归调用ls-files

Currently there is only support for the --cached and --stage modes.目前仅支持--cached--stage模式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM