git submodule update <name of submodule> - 但仍然被修改:<name of submodule>(修改内容)

Sno*_*ash 2 git git-submodules

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

modified:   <name of submodule> (modified content)
Run Code Online (Sandbox Code Playgroud)

我跑:

git submodule update <name of submodule> 
Run Code Online (Sandbox Code Playgroud)

但仍然得到:

modified:   <name of submodule> (modified content)
Run Code Online (Sandbox Code Playgroud)

知道为什么吗?

lar*_*sks 5

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'
Run Code Online (Sandbox Code Playgroud)

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

git submodule update --force
Run Code Online (Sandbox Code Playgroud)

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