如何放弃对 Git 子模块所做的更改?

15

我改变了Git子模块的提交指针:

% git status
# On branch fix
# Your branch is behind 'origin/fix' by 1 commit, and can be fast-forwarded.
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   app/lib (new commits)
#
no changes added to commit (use "git add" and/or "git commit -a")

然而当我执行 git checkout 命令时,没有任何改变:

% git checkout -- app/lib && git status
# On branch fix
# Your branch is behind 'origin/fix' by 1 commit, and can be fast-forwarded.
#
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#   modified:   app/lib (new commits)
#
no changes added to commit (use "git add" and/or "git commit -a")

这里是差异:

% git diff
diff --git a/app/lib b/app/lib
index d670460..83baae6 160000
--- a/app/web-lib
+++ b/app/web-lib
@@ -1 +1 @@
-Subproject commit d670460b4b4aece5915caf5c68d12f560a9fe3e4
+Subproject commit 83baae61804e65cc73a7201a7252750c76066a30

这是为什么发生的任何想法吗?

谢谢!

1个回答

19

当子模块中的 SHA 值发生变化时,Git 并不会自动更新子模块。

你可以使用 git submodule update 命令将子模块更新至预期的 SHA 值, 或者使用 git add app/lib 命令将预期的 SHA 值更改为子模块当前的值。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接