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

标签 git git-submodules

我有一个子模块,当我执行 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

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

关于git submodule update <name of submodule> - 但仍然被修改 : <name of submodule> (modified content),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46911083/

相关文章:

git - 在哪里可以找到 git 发行说明?

linux - 当另一台计算机推送到 bitbucket 时,如何从一台计算机触发 "git pull"?

git - 是否有对上游分支的引用?

git - 如何将 git repo 添加为自身的子模块? (或 : How to generate GitHub Pages programmatically? )

git - 无法 `git submodule foreach git pull`

github - 子模块在 github 页面中的行为如何?

.net - 使用 VS 解决方案的 git 子模块时如何解析 nuget 包

git - 如何在本地更改 git 子模块 url?

git - 处理git blame的全部内容

Ubuntu 上的 git-gui 不显示新目录