What is the difference between the "git subach module foreach git master origin pull" and the "git pull origin master -recurse-subodules"

I have a dotfiles repository where all my vim plugins are stored as submodules, so they are easy to update when they have changes. I thought the two teams did the same, but I noticed that it should not be.

I knew that I had updates to tear down a few submodules, so I ran git pull origin master --recurse-submodules from the root of the parent repository. He seemed to be sorting through each submodule, but only extracting updates from his source repositories.

When I ran git submodule foreach git pull origin master , it actually ran git pull origin master inside each repository, doing both fetch and merge.

What is the point of using --recurse-submodules ? I am a little confused about what he is actually trying to do, and Google is a little mysterious with what I found. I thought maybe your smart people will have a simpler explanation.

+5
source share
2 answers

This option is intended primarily for sampling, all sub-modules perform, not just pull one particular branch, such as the master, for the reasons given in the following two commits:
(note that the bug is fixed in Git 2.11, see the end of this answer)

For git pull this option was introduced in ( commit 7dce19d, November 2010, Git 1.7.4-rc0) :

fetch / pull : add option --recurse-submodules

So far you have had to call " git submodule update " (without the -N|--no-fetch option) or something like " git submodule foreach git fetch " to retrieve new commits in populated submodules from their remote.

This can lead to " (commits not present) " messages on the output of " git diff --submodule " (which is used by " git gui " and " gitk ") after retrieving or pulling new commits in a superproject and is an obstacle to implementing recursive verification of submodules.
In addition, the β€œ git submodule update ” cannot retrieve changes when disconnected, so it was very easy to forget to get the changes in the submodules before disabling them, only to find out later that they are needed.

This patch adds the --recurse-submodules to recursively extract each populated submodule from the url configured in the .git/config submodule at the end of each git fetch or during a git pull to the superproject. Submodule paths are taken from the index.


Commit 88a2197 (March 2011, Git 1.7.5-rc1) explains a bit more:

fetch / pull : overwrite if necessary in submodules

In order to have access to all records of filled submodules referenced by a superproject, it is enough only if the β€œ git fetch ” recursively submodule is required when new entries are written to the records of the superproject.

  • The presence of these commits are extremely useful when using "option --submodule " for " git diff " (that is " git gui " and " gitk " to do with the 1.6.6), since all the sub-modules are made necessary to create access to the descriptive conclusion.
  • Also, the compilation of the merge submodule (added in 1.7.3) depends on the submodule present, which is present in the work .
  • And last but not least: it allows you to disable the work when using submodules , since all the commits necessary for the successful " git submodule update -N " will be automatically loaded.

Thus, we select this mode as the default for extraction and extrusion.


 git pull origin master --recurse-submodules git submodule foreach git pull origin master 

The first should pull out, and not just pull out and be equivalent to the second. Perhaps this is a problem with the parameter:

 git pull --recurse-submodules origin master 

However, this is not the recommended way to update a submodule for this branch: see the next section.


Please note that the correct way to actually pull out of the wizard will register the main branch in the submodule , which makes the Submodule Tracking Wizard

 git config -f .gitmodules submodule.<path>.branch <branch> 

Then a simple git submodule update --remote --recursive .
And the branch to extract / pull is written in the parent repo (in the .gitmodules file), so you don’t even need to remember which branch you need in order for your submodule to be updated.


Git Update 2.11 (Q4 2011)

The presence of a submodule whose repository " .git " is somehow corrupted has caused several commands to return to the cycle of submodules forever.

See commit 10f5c52 (September 01, 2016) Junio ​​C Hamano ( gitster ) .
(merger of Junio ​​C Hamano - gitster - on commit 293c232 , 12 Sep 2016)

+5
source

What is the point of using --recurse-submodules ?

--recurse-submodules will make submodules inside the submodule (it is actually recursive). git submodule foreach git pull origin master will not, it will only do immediate submodules.

0
source

Source: https://habr.com/ru/post/1234815/


All Articles