git git子模块修改文件状态

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6006494/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 10:55:07  来源:igfitidea点击:

git submodule modified files status

gitgit-submodules

提问by Poe

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 文件夹树中添加了一个子模块,但没有更改任何内容,但显示已修改。我该怎么办?

$ 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.

我试过 git submodule update,但它没有做任何事情。

回答by Mark Longair

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 --versionas well for us to be able to help accurately.

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

However, in any case, the output of git diff example.com/soundmanagershould tell you more. If you see output with the same commit name, but with -dirtyadded to the new version, e.g.:

然而,无论如何,输出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

... than that means that git statusin the submodule isn't clean - try cd example.com/soundmanagerand then git statusto see what's going on.

...这意味着git status在子模块中不干净 - 尝试cd example.com/soundmanager然后git status看看发生了什么。

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:

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

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

回答by awe

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/*

回答by blacet wang

I used the following git command to resolve this problem:

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

git submodule update --init  --recursive