如何查看 git 子模块库的状态?

How to see status of a git submodule library?

我在 git 项目中有一个库,它是一个子模块,我将其命名为 service-lib。

serivce-lib 不是我自己或我公司开发的,实际上我被鼓励不要编辑它。

如何检查此模块的 git 状态:

  1. 检查以确保我没有不小心 edited/created 一个文件 其中
  2. 查看开发人员的任何更新(即我可以采用 他们可能添加的任何错误修复)

git 子模块有以下命令来查看子模块状态。

git submodule status path/to/submodule

像处理任何其他 git 存储库一样使用 status 命令


git submodule status

Show the status of the submodules.

This will print the SHA-1 of the currently checked out commit for each submodule, along with the submodule path and the output of git describe for the SHA-1.

Each SHA-1 will be prefixed with - if the submodule is not initialized, + if the currently checked out submodule commit does not match the SHA-1 found in the index of the containing repository and U if the submodule has merge conflicts.

If --recursive is specified, this command will recurse into nested submodules, and show their status as well.

If you are only interested in changes of the currently initialized submodules with respect to the commit recorded in the index or the HEAD, git status and git diff will provide that information too (and can also report changes to a submodule’s work tree).

注意,如果你只有一个子模块,查看它的状态就更简单了:

git submodule

这是因为,在 Git 2.22 (Q2 0219) 之前,git-submodule.txt 和 [=30 的使用文本中都没有记录子模块的默认行为=]-子模块。

参见 commit 68cabbf (15 Feb 2019) by Denton Liu (Denton-L)
(由 Junio C Hamano -- gitster -- in commit c388c12 合并,2019 年 3 月 7 日)

现在 documentation includes:

With no arguments, shows the status of existing submodules.
Several subcommands are available to perform operations on the submodules.