git 子模块更新 <name of submodule> - 但仍然被修改:<name of submodule>(修改内容)

git submodule update <name of submodule> - but still get modified: <name of submodule> (modified content)

我有一个子模块,当我这样做时 git status 我得到:

modified:   <name of submodule> (modified content)

我运行:

git submodule update <name of submodule> 

但仍然得到:

modified:   <name of submodule> (modified content)

知道为什么吗?

modified content 消息的意思正是它所说的:您已经修改了该子模块目录中的文件。 运行 git submodule update 不会丢弃本地更改(因为也许您想要那些)。 update操作更像git pull;只要不与您的本地更改冲突,就会应用新的更改。如果您的本地更改会导致冲突,您会看到如下内容:

error: Your local changes to the following files would be overwritten by checkout:
    src/somefile.c
Please commit your changes or stash them before you switch branches.
Aborting
Unable to checkout '006d23ccca1375a973b7fae0cc351cedb41b812a' in submodule path 'name-of-submodule'

如果要放弃本地更改,可以使用 --force 标志:

git submodule update --force

这将永久放弃您在该子模块目录中所做的任何本地更改。