git submodule tracking latest

后端 未结 1 1238
甜味超标
甜味超标 2020-11-21 23:06

We are moving our (huge) project to git and we are thinking about using submodules. Our plan is to have three different heads in the superproject: release,stable,latest. The

相关标签:
1条回答
  • 2020-11-21 23:45

    Update March 2013

    Git 1.8.2 added the possibility to track branches.

    "git submodule" started learning a new mode to integrate with the tip of the remote branch (as opposed to integrating with the commit recorded in the superproject's gitlink).

    # add submodule to track master branch
    git submodule add -b master [URL to Git repo];
    
    # update your submodule
    git submodule update --remote 
    

    If you had a submodule already present you now wish would track a branch, see "how to make an existing submodule track a branch".

    Also see Vogella's tutorial on submodules for general information on submodules.

    Note:

    git submodule add -b . [URL to Git repo];
                        ^^^
    

    See git submodule man page:

    A special value of . is used to indicate that the name of the branch in the submodule should be the same name as the current branch in the current repository.


    See commit b928922727d6691a3bdc28160f93f25712c565f6:

    submodule add: If --branch is given, record it in .gitmodules

    This allows you to easily record a submodule.<name>.branch option in .gitmodules when you add a new submodule. With this patch,

    $ git submodule add -b <branch> <repository> [<path>]
    $ git config -f .gitmodules submodule.<path>.branch <branch>
    

    reduces to

    $ git submodule add -b <branch> <repository> [<path>]
    

    This means that future calls to

    $ git submodule update --remote ...
    

    will get updates from the same branch that you used to initialize the submodule, which is usually what you want.

    Signed-off-by: W. Trevor King


    Original answer (February 2012):

    A submodule is a single commit referenced by a parent repo.
    Since it is a Git repo on its own, the "history of all commits" is accessible through a git log within that submodule.

    So for a parent to track automatically the latest commit of a given branch of a submodule, it would need to:

    • cd in the submodule
    • git fetch/pull to make sure it has the latest commits on the right branch
    • cd back in the parent repo
    • add and commit in order to record the new commit of the submodule.

    gitslave (that you already looked at) seems to be the best fit, including for the commit operation.

    It is a little annoying to make changes to the submodule due to the requirement to check out onto the correct submodule branch, make the change, commit, and then go into the superproject and commit the commit (or at least record the new location of the submodule).

    Other alternatives are detailed here.

    0 讨论(0)
提交回复
热议问题