我有一个带有 Git 子模块的项目。它来自 ssh://... URL,并且在提交 A 上。提交 B 已被推送到该 URL,我希望子模块检索提交并更改为它。
现在,我的理解是git submodule update
应该这样做,但事实并非如此。它什么都不做(没有输出,成功退出代码)。这是一个例子:
$ mkdir foo
$ cd foo
$ git init .
Initialized empty Git repository in /.../foo/.git/
$ git submodule add ssh://user@host/git/mod mod
Cloning into mod...
user@host's password: hunter2
remote: Counting objects: 131, done.
remote: Compressing objects: 100% (115/115), done.
remote: Total 131 (delta 54), reused 0 (delta 0)
Receiving objects: 100% (131/131), 16.16 KiB, done.
Resolving deltas: 100% (54/54), done.
$ git commit -m "Hello world."
[master (root-commit) 565b235] Hello world.
2 files changed, 4 insertions(+), 0 deletions(-)
create mode 100644 .gitmodules
create mode 160000 mod
# At this point, ssh://user@host/git/mod changes; submodule needs to change too.
$ git submodule init
Submodule 'mod' (ssh://user@host/git/mod) registered for path 'mod'
$ git submodule update
$ git submodule sync
Synchronizing submodule url for 'mod'
$ git submodule update
$ man git-submodule
$ git submodule update --rebase
$ git submodule update
$ echo $?
0
$ git status
# On branch master
nothing to commit (working directory clean)
$ git submodule update mod
$ ...
我也试过git fetch mod
,它似乎做了一个 fetch (但不可能,因为它没有提示输入密码!),但git log
否认git show
存在新的提交。到目前为止,我一直在rm
-ing 模块并重新添加它,但这在原则上是错误的,在实践中也是乏味的。