How to only update specific git submodules?

后端 未结 5 846
盖世英雄少女心
盖世英雄少女心 2020-12-04 19:08

So, updating all my submodules is done by running

git submodule foreach \'git pull origin master\'

How do I update a specific submo

5条回答
  •  情书的邮戳
    2020-12-04 19:34

    How do I update a specific submodule, located in say bundle/syntastic, without updating any other submodules?

    With Git 2.13 (and the help of submodule..update config setting):

    git clone --recurse-submodules="bundle/syntastic"
    git config submodule.syntastic.update "git pull origin master"
    

    The second line (to be executed only once) is needed because the clone --recurse-submodules[=git submodule update --init --recursive immediately after the clone is finished.
    And that would only checkout the submodule at its gitlink recorded SHA1, not at the latest remote origin/master SHA1.
    By adding the submodule..update config setting, you ensure that the selective clone of the submodule will be followed by an update, only for that submodule.


    As part of the Git 2.13 (Q2 2017) "active submodule" feature (see "Ignore new commits for git submodule"), you have this commit bb62e0a from Brandon Williams (bmwill):

    clone: teach --recurse-submodules to optionally take a pathspec

    Teach clone --recurse-submodules to optionally take a pathspec argument which describes which submodules should be recursively initialized and cloned.
    If no pathspec is provided, --recurse-submodules will recursively initialize and clone all submodules by using a default pathspec of ".".
    In order to construct more complex pathspecs, --recurse-submodules can be given multiple times.

    This also configures the 'submodule.active' configuration option to be the given pathspec, such that any future invocation of git submodule update will keep up with the pathspec.

    Additionally the switch '--recurse' is removed from the Documentation as well as marked hidden in the options array, to streamline the options for submodules. A simple '--recurse' doesn't convey what is being recursed, e.g. it could mean directories or trees (c.f. ls-tree).
    In a lot of other commands we already have '--recurse-submodules' to mean recursing into submodules, so advertise this spelling here as the genuine option.

    So the git clone --recursive man page now reads:

    --recurse-submodules[=

    After the clone is created, initialize and clone submodules within based on the provided pathspec.

    If no pathspec is provided, all submodules are initialized and cloned.

    Submodules are initialized and cloned using their default settings.
    The resulting clone has submodule.active set to the provided pathspec, or "." (meaning all submodules) if no pathspec is provided.
    This is equivalent to running git submodule update --init --recursive immediately after the clone is finished. This option is ignored if the cloned repository does not have a worktree/checkout (i.e. if any of --no-checkout/-n, --bare, or --mirror is given)

    Example from the t/t7400-submodule-basic.sh test:

    git clone --recurse-submodules="." \
              --recurse-submodules=":(exclude)sub0" \
              --recurse-submodules=":(exclude)sub2" \
              multisuper multisuper_clone
    

    That would clone and update every submodules, except sub0 and sub2.


    Bonus, with Git 2.22 (Q2 2019) "git clone --recurs" works better.

    See commit 5c38742 (29 Apr 2019) by Nguyễn Thái Ngọc Duy (pclouds).
    (Merged by Junio C Hamano -- gitster -- in commit 2cfab60, 19 May 2019)

    parse-options: don't emit "ambiguous option" for aliases

    Change the option parsing machinery so that e.g. "clone --recurs ..." doesn't error out because "clone" understands both "--recursive" and "--recurse-submodules" to mean the same thing.

    Initially "clone" just understood --recursive until the --recurses-submodules alias was added in ccdd3da ("clone: Add the --recurse-submodules option as alias for --recursive", 2010-11-04, Git v1.7.4-rc0).
    Since bb62e0a ("clone: teach --recurse-submodules to optionally take a pathspec", 2017-03-17, Git v2.13.0-rc0) the longer form has been promoted to the default.

    But due to the way the options parsing machinery works this resulted in the rather absurd situation of:

    $ git clone --recurs [...]
    error: ambiguous option: recurs (could be --recursive or --recurse-submodules)
    

    Add OPT_ALIAS() to express this link between two or more options and use it in git-clone.

提交回复
热议问题