Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git submodules: specify a specific SHA?

Tags:

I'm referencing a git submodule in my project, and now need to reference a specific SHA in the target git repo.

# .gitmodules [submodule "vendor/plugins/ssl_requirement"]   path = vendor/plugins/ssl_requirement   url = git://github.com/retr0h/ssl_requirement.git 

The SHA I want is bc96ad96407a72a60e0542cf3b0cecc6ff9e278e.

like image 242
Zubin Avatar asked Jan 11 '12 02:01

Zubin


People also ask

How do I change a submodule to a specific commit?

Use the git submodule update command to set the submodules to the commit specified by the main repository. This means that if you pull in new changes into the submodules, you need to create a new commit in your main repository in order to track the updates of the nested submodules.

Are git submodules a good idea?

Git submodules may look powerful or cool upfront, but for all the reasons above it is a bad idea to share code using submodules, especially when the code changes frequently. It will be much worse when you have more and more developers working on the same repos.

How do I initialize a git submodule?

If you already cloned the project and forgot --recurse-submodules , you can combine the git submodule init and git submodule update steps by running git submodule update --init . To also initialize, fetch and checkout any nested submodules, you can use the foolproof git submodule update --init --recursive .


1 Answers

Submodules, by definition, always reference particular SHA1 in the subproject. That SHA1 isn't expressed in the .gitmodules file, but is instead expressed as the entry in the tree object that contains the submodule. The way you set this in git is by cding into the submodule, checking out the SHA1 you want, then cding back to the parent repo and committing your change, which will show up just like a changed file.

So in your case what you can do is

cd vendor/plugins/ssl_requirement git checkout bc96ad96407a72a60e0542cf3b0cecc6ff9e278e cd .. git add ssl_requirement # commit whenever you're ready 
like image 55
Lily Ballard Avatar answered Sep 23 '22 14:09

Lily Ballard