【问题标题】:How to list git submodules that have not been pushed to origin?如何列出尚未推送到源的 git 子模块?
【发布时间】:2015-07-07 14:17:24
【问题描述】:

有时我忘记推送一个 git 子模块。有没有办法显示哪些 git 子模块在原点之前,没有被推送?

【问题讨论】:

    标签: git push git-submodules git-push


    【解决方案1】:

    每个子模块的简单状态可以很好地表示它们各自的状态:

    git submodule foreach "git status || true"
    

    请参阅“Use git submodule foreach with function”了解更复杂的脚本,以结合git submodule foreach 命令运行。

    只有在以下情况下才会显示推送状态:

    • your module is configured to follow a branch。 (否则,子模块被检出为分离头,提交状态为空,推送状态不存在)

      git config -f .gitmodules submodule.<path>.branch <branch>
      git submodule update --init --remote
      
    • 一个分支已经被签出(并且提交完成)

      cd asubmodule
      git checkout master
      # add and commit
      

    (见“Git submodule is in “detached head” state after cloning and submodule update”)

    然后该命令将起作用(例如'compose' submodule of the project b2d):

    VonC@voncvb MINGW64 /c/Users/VonC/prog/b2d (master)
    $ git submodule foreach "git status || true"
    Entering 'compose'
    On branch master
    Your branch is ahead of 'origin/master' by 1 commit.
      (use "git push" to publish your local commits)
    nothing to commit, working directory clean
    

    【讨论】:

    • @adrelanos 它将显示推送状态(我刚刚测试过),但我的答案缺少使推送状态可见的必要步骤。我已经修改了我的答案。
    猜你喜欢
    • 1970-01-01
    • 2021-03-08
    • 1970-01-01
    • 2015-05-28
    • 1970-01-01
    • 2014-07-31
    • 2017-10-05
    • 2011-08-22
    • 2011-01-24
    相关资源
    最近更新 更多