Reputation: 5648
The problem: Can I pin git modules to specific commits?
I am writing a build script to produce an artifact which is a Zip archive of multiple submodules with a few requirements.
Here is the rub:
If I checkout:
git clone git@whatever:thing/mybuildscipt
and then do
git submodule update --init
I need the exact commit number of each submodule to be recorded in the build script's repo (ideally in .gitmodules) so that in the future, if I should do
git checkout 1.2.3
git submodule update
I am going to the same submodules as they were at when the build script repo was tagged with "1.2.3".
Long ago, this is exactly how git submodules worked: They were pinned to a specific commit and that commit hash was actually in the .gitmodule
- I need that behavior and it's not at all clear to me, based on my research, if it's still possible.
Here is a summary of the commands being run the in build script, so that you can get the idea what is to be accomplished. Ultimately if I checkout a specific version of the git repo that contains the build script, it should produce an identical zip archive as before.
export NEXT_VERSION=$(
git tag --sort=committerdate \
| tail -1 \
| awk -F '.' '{print $1"."$2"." $3 +1}')
git submodule update --init
# remove the .git dir to save space
git submodule | awk '{print $2}' | xargs -I {} -n 1 rm -fR {}/.git
git submodule | awk '{print $2}' | xargs zip -qr ${FILE_NAME}
# push to object storage
mc cp ${FILE_NAME} ${ALIAS}/${bucket}/${FILE_NAME}
# tag
git tag ${NEXT_VERSION}
# update tags
git push --tags origin
Upvotes: 2
Views: 1465
Reputation: 1324218
Where is the commit hash for the submodules stored then?
In a gitlink, a SHA1 recorded as a special entry in the index.
git ls-files --stage|grep 160000
The all purpose of a submodule is to record/restore a specific SHA1 of its associated repository.
One possible scenario where the same SHA1 is not restore is if your submodule is configured to follow a branch, and you are using a git submodule update --remote
option.
Upvotes: 1