How to combine git submodules

I just made git merge in the application, I resolved a lot of conflicts

But when I execute git status, I can see the list of submodules with (new commits) in the message, it looks like the version of the submodules (branch / tag) is not updated.

For example: changed: plugins /myplugin.git(new commits)

So how to update submodules with versions (using)

I get this in git bash

my_app (current_branch |MERGING), 

so when i do git status i get a list of submodules as below

  modified: plugins/plugin1.git (new commits) modified: plugins/plugin2.git (new commits) modified: plugins/plugin3.git (new commits) modified: plugins/plugin4.git (new commits) 

How to resolve this

+7
git git-merge git-submodules
source share
3 answers

To update the contents of the submodule to the new SHA1, this should be enough:

 # the submodule content needs to be updated git submodule update --init # the parent repo needs to record the new submodule SHA1 git add plugins/myplugin 
+1
source share

Let's say you have two branches master and hotifx . In master , the submodule head is located at 123456 in hotfix with abcdef . (let's say that abcdef newer than 123456 ). If you checked master and change hotfix , the head of the submodule will move to abcdef , but the code in the submodule will not be checked for this new head. If you type git diff , you will see that the submodule points to 123456 , but this is not true since you want to point to abcdef . If you log in now

 git add pathToSubmodule 

the old 123456 added to the index. This is an incorrect fix. What you need to do is move your head to the correct commit, and this is done with a simple call

 git submodule update 
+3
source share

Submodules mainly indicate a specific commit in the submodule that was used when committing in the parent git repository. After your merge, it seems that the submodules are ahead of what is expected after the merge. You have two options:

  • go back to commit where the submodule currently points to
  • update parent repository to use new submodule states

The first option was marked by others as

 git submodule update 

The second option, and I think this is what you are asking for, is done with

 git add plugins/plugin?.git git commit -m 'update submodules' 

which will update your HEAD state to maintain the current links of the submodule.


You can check what happens by looking at

 git ls-tree HEAD | grep 'plugin1.git' 

before and after updating the submodule. Compare this link with the current commit in this plugin:

 cd plugins/plugin1.git git rev-parse HEAD 
+1
source share

All Articles