Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
828 views
in Technique[技术] by (71.8m points)

git - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...