Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I update a git submodule without checking it out

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.

like image 838
Dave Halter Avatar asked Mar 31 '14 14:03

Dave Halter


2 Answers

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

like image 74
Alex Avatar answered Oct 12 '22 09:10

Alex


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!

like image 22
Louis Caron Avatar answered Oct 12 '22 08:10

Louis Caron