Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change HEAD of git submodule

The Project is having one sub module and is pointing to one particular SHA (ex 62726c) of that submodule.

So each time on running git submodule update --init the submodule directory is showing the changes of that SHA (62726c) only.

Recently I made change to the submodule and pushed the changes SHA (f81611) but as mentioned above the HEAD of the submodule is still pointing to old SHA 62726c .

like image 985
Jyotsna Saroha Avatar asked Aug 11 '14 10:08

Jyotsna Saroha


2 Answers

When doing git submodule update --init, you checkout the submodule to the revision registered by the project, which hasn't been updated, that's why you always see it reverted.

To change the revision of the submodule for the super project, check out the submodule to the SHA1 you want:

git checkout f81611

From the main project you'll see that the submodule is listed as being modified (git status). You need to commit this modification, as if the submodule was a normal file:

git add <path-to-submodule>
git commit -m "Update submodule XX so that it does YY"
like image 191
CharlesB Avatar answered Oct 19 '22 10:10

CharlesB


The other option is to make your submodule follow a particular branch:
See "Git submodules: Specify a branch/tag"

Then a git submodule update --init --recursive --remote would be enough to check out the latest from that branch for all your repos which have specified a branch to follow.

If your pushed change SHA (f81611) was push on master of the repo, then git submodule update --init --remote would update the content of that submodule repo as used in the main parent repo.

like image 40
VonC Avatar answered Oct 19 '22 09:10

VonC