代码之家  ›  专栏  ›  技术社区  ›  Anh-Tuan Mai

Git-在子模块“Git status”中不提供根repo中的“is-update”信息

  •  0
  • Anh-Tuan Mai  · 技术社区  · 5 年前

    我有一个子模块的git回购。 git status 提供分支与远程分支的状态比较。如:

    On branch develop
    Your branch is up-to-date with 'origin/develop'.
    

    但是在子模块repo中,我没有第二行。 如何在所有子模块中获取这些信息?谢谢。

    0 回复  |  直到 5 年前
        1
  •  1
  •   joanis Ankur Kumar Srivastava    5 年前

    当您使用Git子模块时,默认情况下子模块的状态是分离的。

    当你跑的时候 git submodule update ,无论是第一次提交还是其他人为子模块推送了新的提交,Git都将签出根项目所说的子模块应该位于的sha1。

    例如。

    > git submodule update
    > cd <submodule>
    > git status
    HEAD detached at 59fe3c5232
    nothing to commit, working directory clean
    

    现在,我可以使用 git log :

    > git log --all --decorate --graph --format=oneline
    * 59fe3c5232 (HEAD, origin/master, master) Commit details
    * 8762eca8d9 Older commit
    ...
    

    当有分支时,日志会更有趣:查找 HEAD

    以我为例,如果我现在这样做的话 git checkout master 在子模块中,我仍然在根repo所期望的提交上,但是我也在跟踪子模块中的主分支。

    > git checkout master
    > git status
    On branch master
    Your branch is up-to-date with 'origin/master'.
    nothing to commit, working directory clean
    

    但是如果我签出的提交不是根repo所期望的,那么根repo会认为这是一个需要提交的更改(做 git diff git status 在根回购中看到。)

    如果团队中的其他人将提交推送到子模块,那么下次我更新根repo并执行 git子模块更新 ,我会回到分离头模式。

    推荐文章