Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the current commit id of specified submodule

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?

like image 840
eszik.k Avatar asked Sep 01 '15 08:09

eszik.k


People also ask

How can I see my submodule commit?

If you want to check for new work in a submodule, you can go into the directory and run git fetch and git merge the upstream branch to update the local code. Now if you go back into the main project and run git diff --submodule you can see that the submodule was updated and get a list of commits that were added to it.

Where does git store submodule commit ID?

It is stored in Git's object database directly. The tree object for the directory where the submodule lives will have an entry for the submodule's commit (this is the so-called "gitlink").

Does git pull pull submodules?

Pulling with submodules. Once you have set up the submodules you can update the repository with fetch/pull like you would normally do. To pull everything including the submodules, use the --recurse-submodules and the --remote parameter in the git pull command .


2 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".

like image 174
VonC Avatar answered Sep 24 '22 18:09

VonC


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)
... 
like image 36
priyanka Avatar answered Sep 24 '22 18:09

priyanka