'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.
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.
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?
Solution 1:[1]
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
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.
Solution 2:[2]
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.
See commit 290eada (23 Feb 2022) by Jonathan Tan (jhowtan).
(Merged by Junio C Hamano -- gitster -- in commit 7a4e06c, 06 Mar 2022)
ls-files: support--recurse-submodules --stageSigned-off-by: Jonathan Tan
e77aa33 ("
ls-files: optionally recurse into submodules", 2016-10-10, Git v2.11.0-rc0 -- merge listed in batch #11) taughtls-filesthe--recurse-submodulesargument, but only in a limited set of circumstances.In particular,
--stagewas unsupported, perhaps because there was norepo_find_unique_abbrev(), which was only introduced in 8bb9557 ("sha1-name.c``: addrepo_find_unique_abbrev_r()", 2019-04-16, Git v2.22.0-rc0 -- merge listed in batch #8).This function is needed for using
--recurse-submoduleswith --stage.
git ls-files now includes in its man page:
--recurse-submodules:Recursively calls
ls-fileson each active submodule in the repository.Currently there is only support for the
--cachedand--stagemodes.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ElpieKay |
| Solution 2 | VonC |
