git 子模块修改文件状态
我在我的主 git 文件夹树中添加了一个子模块,没有更改任何内容,但它显示已修改。我该怎么办?
$ git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: example.com/soundmanager
#
no changes added to commit (use "git add" and/or "git commit -a")
我尝试过 git 子模块更新,但它没有做任何事情。
I've added a submodule in my main git folder tree and haven't changed anything but it's showing up modified. What do I do about this?
$ git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: example.com/soundmanager
#
no changes added to commit (use "git add" and/or "git commit -a")
I've tried a git submodule update, but it doesn't do anything.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
与最新版本的 git 相比,报告 git 子模块状态的方式发生了很大变化,因此您应该真正包含 git --version 的输出,以便我们能够准确地提供帮助。
但是,无论如何,
git diff example.com/soundmanager
的输出应该告诉您更多信息。如果您看到具有相同提交名称的输出,但将-dirty
添加到新版本,例如:... 则意味着子模块中的
git status
不存在t clean - 尝试cd example.com/soundmanager
,然后git status
看看发生了什么。另一方面,如果您看到不同的提交版本,例如:
...这意味着您的子模块所在的版本(即您从
cd example.com/soundmanager && git show HEAD< /code>)与主项目树中提交的版本不同(即您从 git rev-parse HEAD:example.com/soundmanager 中看到的版本)。如果前者是正确的,您应该在主项目中添加并提交子模块的新版本,类似于:
另一方面,如果后者是您想要的,您可以更改子模块所在的版本:
The way that the status of git submodules is reported has changed a lot over recent versions of git, so you should really include the output of
git --version
as well for us to be able to help accurately.However, in any case, the output of
git diff example.com/soundmanager
should tell you more. If you see output with the same commit name, but with-dirty
added to the new version, e.g.:... than that means that
git status
in the submodule isn't clean - trycd example.com/soundmanager
and thengit status
to see what's going on.On the other hand, if you see different commit versions, e.g.:
... that means that the version that your submodule is at (i.e. what you see from
cd example.com/soundmanager && git show HEAD
) is different from the version committed in the main project's tree (i.e. what you see fromgit rev-parse HEAD:example.com/soundmanager
). If the former is right, you should add and commit the new version of the submodule in your main project, with something like:On the other hand, if the latter is what you want, you can change the version that the submodule is at with:
我使用以下 git 命令来解决这个问题:
I used the following git command to resolve this problem:
我通过专门添加目录而不是仅添加新目录的内容来错误地添加子模块,从而进入这种状态。
我只需要像这样删除子模块:
然后像我最初打算的那样添加内容:
I got in this state by mistakenly adding a submodule by specifically adding a directory instead of just adding the content of a new directory.
I needed just to remove the submodule like this:
And then add the contents like I intended to in the first place: