Search code examples
gitgit-submodules

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

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