Eagle
Eagle

Reputation: 3474

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?

Upvotes: 1

Views: 228

Answers (2)

VonC
VonC

Reputation: 1324218

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 --stage

Signed-off-by: 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.

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).

This function is needed for using --recurse-submodules with --stage.

git ls-files now includes in its man page:

--recurse-submodules:

Recursively calls ls-files on each active submodule in the repository.

Currently there is only support for the --cached and --stage modes.

Upvotes: 0

ElpieKay
ElpieKay

Reputation: 30868

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.

Upvotes: 1

Related Questions