문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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!

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top