Better Git: How to find out what submodules there are in a different branch
Posted: February 5, 2013 Filed under: Better Git Leave a commentGenerally speaking Git is fantastic and easy to use – one of the few pain points is where submodules butt heads with branches.
Far from solving all the problems in related to this – I’ve found an easy way to find out what submodules are in a branch, commit, or tag without having to check that reference out. This method also shows you the commits that each submodule is currently pointing to.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Where <ref> should be replaced with a branch name, tag name, or commit hash. | |
git ls-tree -rt <reference> | grep 'commit [0-9A-z]' |
The ls-tree command is fairly simple, its like running the ls unix command but includes git information – like the type of object each item is and the hash reference for that object. That command can also be used on a specific directory also by using <reference>:<path>. The -r flag makes it recursive so that is searches through all the subdirectories in the branch.
The second part of this is a simple grep command, that filters the results by those of type “commit”, which is how ls-tree represents submodules. I’ve included a pattern to match the word commit followed by the SHA1 hash – to avoid getting items that have the word commit as part of a folder or filename.
Hope this helps someone out there – it took me a while to figure out how to do this.