git 子模块修改文件状态

发布于 2024-11-07 03:32:51 字数 438 浏览 0 评论 0原文

我在我的主 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蓦然回首 2024-11-14 03:32:51

与最新版本的 git 相比,报告 git 子模块状态的方式发生了很大变化,因此您应该真正包含 git --version 的输出,以便我们能够准确地提供帮助。

但是,无论如何,git diff example.com/soundmanager 的输出应该告诉您更多信息。如果您看到具有相同提交名称的输出,但将 -dirty 添加到新版本,例如:

diff --git a/example.com/soundmanager b/example.com/soundmanager
--- a/example.com/soundmanager
+++ b/example.com/soundmanager
@@ -1 +1 @@
-Subproject commit c5c6bbaf616d64fbd873df7b7feecebb81b5aee7
+Subproject commit c5c6bbaf616d64fbd873df7b7feecebb81b5aee7-dirty

... 则意味着子模块中的 git status 不存在t clean - 尝试cd example.com/soundmanager,然后git status看看发生了什么。

另一方面,如果您看到不同的提交版本,例如:

diff --git a/example.com/soundmanager b/example.com/soundmanager
index c4478af..c79d9c8 160000
--- a/example.com/soundmanager
+++ b/example.com/soundmanager
@@ -1 +1 @@
-Subproject commit c4478af032e604bed605e82d04a248d75fa513f7
+Subproject commit c79d9c83c2864665ca3fd0b11e20a53716d0cbb0

...这意味着您的子模块所在的版本(即您从 cd example.com/soundmanager && git show HEAD< /code>)与主项目树中提交的版本不同(即您从 git rev-parse HEAD:example.com/soundmanager 中看到的版本)。如果前者是正确的,您应该在主项目中添加并提交子模块的新版本,类似于:

git add example.com/soundmanager
git commit -m "Update the soundmanager submodule"

另一方面,如果后者是您想要的,您可以更改子模块所在的版本:

git submodule update 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.:

diff --git a/example.com/soundmanager b/example.com/soundmanager
--- a/example.com/soundmanager
+++ b/example.com/soundmanager
@@ -1 +1 @@
-Subproject commit c5c6bbaf616d64fbd873df7b7feecebb81b5aee7
+Subproject commit c5c6bbaf616d64fbd873df7b7feecebb81b5aee7-dirty

... than that means that git status in the submodule isn't clean - try cd example.com/soundmanager and then git status to see what's going on.

On the other hand, if you see different commit versions, e.g.:

diff --git a/example.com/soundmanager b/example.com/soundmanager
index c4478af..c79d9c8 160000
--- a/example.com/soundmanager
+++ b/example.com/soundmanager
@@ -1 +1 @@
-Subproject commit c4478af032e604bed605e82d04a248d75fa513f7
+Subproject commit c79d9c83c2864665ca3fd0b11e20a53716d0cbb0

... 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 from git 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:

git add example.com/soundmanager
git commit -m "Update the soundmanager submodule"

On the other hand, if the latter is what you want, you can change the version that the submodule is at with:

git submodule update example.com/soundmanager
心意如水 2024-11-14 03:32:51

我使用以下 git 命令来解决这个问题:

git submodule update --init  --recursive

I used the following git command to resolve this problem:

git submodule update --init  --recursive
压抑⊿情绪 2024-11-14 03:32:51

我通过专门添加目录而不是仅添加新目录的内容来错误地添加子模块,从而进入这种状态。

我只需要像这样删除子模块:

git rm --cached path/to/my/new_directory

然后像我最初打算的那样添加内容:

git add path/to/my/new_directory/*

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:

git rm --cached path/to/my/new_directory

And then add the contents like I intended to in the first place:

git add path/to/my/new_directory/*
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文