How do I update a git submodule without checking it out
Asked Answered
U

3

12

I am using a git submodule in a very usual way. The way how people typically update a submodule is by checking it out, pulling something in the submodule and then commiting outside.

Now, I typically don't develop those modules in the same place. For me it's more comfortable to develop those two modules in different places. How do I just tell my git project that one submodule has changed and is now at commit XYZ?

I think there's a chance that there's a setting somewhere in .git that I could modify.

Utley answered 31/3, 2014 at 14:56 Comment(0)
D
12

you can do with this, as follows:

git update-index --add --cacheinfo  mode,sha1,submodule_path

the mode value can get from git ls-files --stage submodule_path

git update-index reference

Dishabille answered 22/11, 2020 at 2:37 Comment(0)
B
12

A self-explanatory example :

git update-index --cacheinfo 160000,03d7dff560ac8ed64f16e763204b04ce91ca5faf,submodules/submodule

Explanation:

  • 160000 : mode; here it indicates a directory (see doc and search for 160000)
  • 03d7dff560ac8ed64f16e763204b04ce91ca5faf: the commit id (or commit hash or sha-1) in the submodule repository to which you want to point from your current repository
  • submodules/submodule: path the the submodule location in the git repository, no trailing slash (gives error), no .git

Remember, this only updates the index, you are still expected to commit the change!

Bunker answered 6/5, 2022 at 7:10 Comment(0)
M
-6

You need to go into the directory where your submodule is, make sure to checkout the branch you want, and do a pull.

So if your submodule is that 'jedi' directory I see in the repo you linked, you need to do the following.

cd jedi
git checkout <desired_branch>
git pull origin <desired_branch>

If you want to update your super repository (the one containing the submodule), then you need to back up to the root of that repo and commit the changed state of the submodule.

cd ..
git add jedi
git commit -m 'updating the jedi submodule'

Then you would want to push up this commit to share it with other people.

Morty answered 31/3, 2014 at 15:6 Comment(2)
I know that. But I really want to do it without checking it out. -> see title. And since usually you can change things by hand, it could be somewhere in the .git directory.Utley
The reason you have to checkout master inside the submodule, is because by default updating the submodule from the super repository puts that submodule in whats called a "headless state". So, are you trying to figure out how to stop git-submodule update from putting your submodules in a headless state?Morty

© 2022 - 2024 — McMap. All rights reserved.