1

How does one recursively list the files in a git branch, including the contents within the commit in a submodule that the branch references? The branch is currently not checked out, and I want to access the contents without checking out that branch.

This is similar to this question, but the question I am raising is for querying a branch not currently checked out.

Unlike git ls-files, git ls-tree does not have a --recurse-submodules option.

intervort
  • 95
  • 4
  • 1
    [`git submodule foreach`](https://git-scm.com/docs/git-submodule#Documentation/git-submodule.txt-foreach--recursiveltcommandgt) works on **checked out submodules** so the simplest (not the most effective) way is to checkout the branch, run `git ls-files --recurse-submodules` and checkout back the current branch. The second simple not effective way is to clone/copy the current repository to a temporary one, checkout the branch, list files and remove the temporary directory. – phd Apr 19 '23 at 17:26
  • 1
    Without checking out the branch the task is quite hard — a script must get `.gitmodules` from the branch, run over the submodules manually (without using `git submodule foreach`), for every submodule find out the commit, list files in the commit, check if the submodule has its own submodules, recurse. The entire code could be simplified in assumption the tree of submodules is identical to the currently checked out branch; then `git submodule foreach` could be used. – phd Apr 19 '23 at 17:28

0 Answers0