I want get the current commit id of the specified submodule. I thought when I cd into submodule directory and run git rev-parse HEAD
i get this after I noticed this is a superproject current id.
Tried git submodule status | grep <submodule_name>
also but its to slow to me. Any idea how to get this information little bit faster?

- 1,729
- 4
- 17
- 40
5 Answers
First, as commented by brookbot
, git submodule status
will print the SHA-1 of the currently checked out commit for each submodule, along with the submodule path and the output of git describe for the SHA-1.
See my other answer below.
You can start with git ls-files -s
(as in this answer)
cd /path/to/parent/repo
git ls-files -s yourSubmodule
Note the absence of a trailing '/
' after yourSubmodule
(which is the root folder of the checked out submodule)
That will give the mode and sha1 associated with the gitlink (special entry in the index of the parent repo)
160000 4d77d23305c5623356955ef9f908f4ec76780ba9 0 yourSubmodule
(The '0' is for the stage number)
Alternatives:
cd /path/to/repo/parentFolder/of/submodule
git ls-tree @ yourSubmodule
git rev-parse @:./yourSubmodule
The rev-parse
only returns the submodule SHA1.
As commented by heloman, you can also find the SHA1 with:
git rev-parse HEAD:path-to-your-sub-module
See more in "How to see which commit a git submodule points at".

- 1,262,500
- 529
- 4,410
- 5,250
-
Note (following the downvote): I forgot the `-s` in `git ls-file -s`. I have edited the answer and added two other alternatives. – VonC Jul 04 '17 at 15:11
-
3`git rev-parse HEAD:path-to-your-sub-module` also works. – heLomaN May 19 '21 at 02:36
-
@heLomaN Good point. I have included your comment in the answer for more visibility. – VonC May 20 '21 at 08:09
-
1`git submodule status` also works – brookbot Mar 23 '22 at 19:46
-
@brookbot Thank you. Good point. I have included your comment in the answer for more visibility. – VonC Mar 23 '22 at 20:08
Open your shell in the required project folder and then type the following git
command:
git submodule
The resulting output would look like:
<module commit> <module-path> (<module-branch)
...

- 18,845
- 10
- 77
- 85

- 159
- 1
- 3
-
1This is really
git submodule status
and documented ingit help submodules
– brookbot Mar 23 '22 at 19:38
git submodule status | grep <submodule_name>
also but its to slow to me
Starting with Git 2.16 (Q4 2017, two years after the OP's question), this should be faster (even though my previous answer remains a viable alternative).
See commit a9f8a37, commit 9f580a6 (06 Oct 2017), and commit 74a1064 (29 Sep 2017) by Prathamesh Chavan (pratham-pc
).
(Merged by Junio C Hamano -- gitster
-- in commit a1bf46e, 06 Nov 2017)
submodule
: port submodule subcommand 'status' from shell to CMentored-by: Christian Couder
Mentored-by: Stefan Beller
Signed-off-by: Prathamesh ChavanThis aims to make
git submodule
'status' a built-in. Hence, the functioncmd_status()
is ported from shell to C. This is done by introducing four functions:module_status()
,submodule_status_cb()
,submodule_status()
andprint_status()
.The function
module_status()
acts as the front-end of the subcommand. It parses subcommand's options and then calls the functionmodule_list_compute()
for computing the list of submodules. Then this functions callsfor_each_listed_submodule()
looping through the list obtained.Then
for_each_listed_submodule()
callssubmodule_status_cb()
for each of the submodule in its list. The functionsubmodule_status_cb()
callssubmodule_status()
after passing appropriate arguments to the funciton. Functionsubmodule_status()
is responsible for generating the status each submodule it is called for, and then callsprint_status()
.Finally, the function
print_status()
handles the printing of submodule's status.Function
set_name_rev()
is also ported fromgit submodule
to the submodule--helper builtin functioncompute_rev_name()
, which now generates the value of the revision name as required.
But.. The way "git submodule
status" reports an initialized but not yet populated submodule has not been reimplemented correctly when a part of the "git submodule
" command was rewritten in C, which has been corrected with Git 2.26 (Q1 2020)
See commit f38c924 (02 Feb 2020), and commit 3b2885e, commit ace912b (24 Jan 2020) by Peter Kaestle (``).
(Merged by Junio C Hamano -- gitster
-- in commit f2dcfcc, 14 Feb 2020)
submodule
: fix status of initialized but not cloned submodulesSigned-off-by: Peter Kaestle
Original bash helper for "
submodule status
" was doing a check for initialized but not cloned submodules and prefixed the status with a minus sign in case no.git
file or folder was found inside the submodule directory.This check was missed when the original port of the functionality from bash to C was done.
This is not the pretiest, but if you cd cd
into the subomdule, you can just git log | head -1

- 1,352
- 2
- 13
- 31