无法摆脱 git 子模块

发布于 2024-09-11 10:24:07 字数 2826 浏览 7 评论 0原文

我向我的 Rails 3 项目添加了一些 Haml 模板

git clone git://github.com/psynix/rails3_haml_scaffold_generator.git lib/generators/haml

,但当我尝试编辑其中一些文件时,却发现这是一个子模块,因此我无法提交在 lib/generators/ 中所做的更改haml 目录。现在,每次我 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:   lib/generators/haml
#
no changes added to commit (use "git add" and/or "git commit -a")

git add lib/generators/haml 没有效果。我真的只想拥有文件,而不是子模块,但我发现子模块无法删除:

> git rm --cached lib/generators/haml
rm 'lib/generators/haml'
> git status

# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   deleted:    lib/generators/haml
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   lib/generators/

> git commit -m "Removed submodule"

[master 02ae4c7] Removed submodule
 1 files changed, 0 insertions(+), 1 deletions(-)
 delete mode 160000 lib/generators/haml

> git status

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   lib/generators/
nothing added to commit but untracked files present (use "git add" to track)

> git add lib/generators/haml
> git status

# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   lib/generators/haml
#
# 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:   lib/generators/haml

> git commit -m "Re-added lib/generators/haml"

[master c966912] Re-added lib/generators/haml
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 160000 lib/generators/haml

> git status

# 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:   lib/generators/haml

额外的 git add 是无用的。如果我尝试 git rm -rf lib/generators/haml,我就会明白

fatal: git rm: 'lib/generators/haml': Operation not permitted

它不会死!我查过如何删除子模块,但在这种情况下,没有.submodules 文件,.git/config 中也没有提及子模块。然而,如果我运行 git submodule update ,我会

No submodule mapping found in .gitmodules for path 'lib/generators/haml'

删除该目录,但得到相同的结果!这是怎么回事?我是否需要创建一个 .gitmodules 文件才能删除子模块?

I added some Haml templates to my Rails 3 project with

git clone git://github.com/psynix/rails3_haml_scaffold_generator.git lib/generators/haml

only to find, when I tried to edit some of those files, that this was a submodule, so I couldn't commit changes that I made within the lib/generators/haml directory. Now every time I git status, I get

# 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:   lib/generators/haml
#
no changes added to commit (use "git add" and/or "git commit -a")

but git add lib/generators/haml has no effect. I really just want to have the files, not a submodule, but I'm finding the submodule impossible to get rid of:

> git rm --cached lib/generators/haml
rm 'lib/generators/haml'
> git status

# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   deleted:    lib/generators/haml
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   lib/generators/

> git commit -m "Removed submodule"

[master 02ae4c7] Removed submodule
 1 files changed, 0 insertions(+), 1 deletions(-)
 delete mode 160000 lib/generators/haml

> git status

# On branch master
# Your branch is ahead of 'origin/master' by 1 commit.
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#   lib/generators/
nothing added to commit but untracked files present (use "git add" to track)

> git add lib/generators/haml
> git status

# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#   new file:   lib/generators/haml
#
# 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:   lib/generators/haml

> git commit -m "Re-added lib/generators/haml"

[master c966912] Re-added lib/generators/haml
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 160000 lib/generators/haml

> git status

# 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:   lib/generators/haml

Additional git adds are useless. If I try git rm -rf lib/generators/haml, I get

fatal: git rm: 'lib/generators/haml': Operation not permitted

It just won't die! I've looked up how to delete submodules, but in this case, there is no .submodules file, nor is there any mention of the submodule in .git/config. Yet if I run git submodule update, I get

No submodule mapping found in .gitmodules for path 'lib/generators/haml'

I deleted the directory, but I get the same results! What's going on? Do I need to create a .gitmodules file just to delete the submodule?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(3

落日海湾 2024-09-18 10:24:07

如果没有子模块,它(即“haml”)是否可能实际上不是子模块?

git clone git://github.com/psynix/rails3_haml_scaffold_generator.git lib/generators/haml

意思是:创建 lib/generators/haml 目录,并在其中签出 git://github.com/psynix/rails3_haml_scaffold_generator.git 的 master 分支。

事实上,您可以不从新存储库的根目录(lib/generators/haml)执行git status,而是从上面三个级别(其中lib< /code> is) 意味着您已经在存储库中克隆了存储库。

两个存储库都可以独立工作,但您应该将 lib/generators/haml 添加到父存储库的 .gitignore 中(例如,点击 所以问题)。

If there is no submodule, is it possible it (i.e. 'haml') is actually not a submodule?

git clone git://github.com/psynix/rails3_haml_scaffold_generator.git lib/generators/haml

means: create lib/generators/haml directory, and checkout in it the master branch of git://github.com/psynix/rails3_haml_scaffold_generator.git.

The fact that you can do a git status not from the root of your new repo ( lib/generators/haml), but three levels above (where lib is) means you have clone a repo within a repo.

Both repo can work independently, but you should add lib/generators/haml to the .gitignore of the parent repo (like in hits SO question).

梦幻的心爱 2024-09-18 10:24:07

如果子模块具有未跟踪的文件,则该子模块会在 git status 中显示为已修改。如果您调用 git diff lib/generators/haml ,您很可能会看到类似这样的内容:

diff --git a/lib/generators/haml b/lib/generators/haml
index 3019fec..653c59a 160000
--- a/lib/generators/haml
+++ b/lib/generators/haml
@@ -1 +1 @@
-Subproject commit 653c59ad72925c9ccbde67e8e484e15d4b6dd25d
+Subproject commit 653c59ad72925c9ccbde67e8e484e15d4b6dd25d-dirty

这意味着在该子模块内还剩下一些未跟踪的文件。它们不能通过父项目中的命令添加;相反,您应该遍历到 sumbodule 并添加它们(或将条目添加到 .gitignore)...或者您可以忽略状态消息。

最新的 git 版本(我认为是 1.7.1)在状态中显示了此信息:

# 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:   lib/generators/haml (untracked content)

The submodule is shown in git status as modified if it has untracked files. If you invoke git diff lib/generators/haml, you'll most likeyl see something like this:

diff --git a/lib/generators/haml b/lib/generators/haml
index 3019fec..653c59a 160000
--- a/lib/generators/haml
+++ b/lib/generators/haml
@@ -1 +1 @@
-Subproject commit 653c59ad72925c9ccbde67e8e484e15d4b6dd25d
+Subproject commit 653c59ad72925c9ccbde67e8e484e15d4b6dd25d-dirty

This means that inside this submodule are some untracked files left. They can't be added through commands in the parent project; instead you should traverse into the sumbodule and add them (or add entries to .gitignore)... Or you can just ignore the status message.

The latest git version (1.7.1, I think) shows this information in status:

# 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:   lib/generators/haml (untracked content)
攀登最高峰 2024-09-18 10:24:07

您可以使用:

git add lib/generators/haml/

将子模块中的文件添加到 HEAD 并删除子模块。但话又说回来,它可能不起作用,因为你实际上没有子模块。

请注意,路径后面有一个尾部斜杠。如果你把这个 git 删除子模块并将其放入 HEAD 中,与: 不同的是,

git add lib/generators/haml

它只会更改要从 git submodules 中的子模块检出的提交。

You could have used:

git add lib/generators/haml/

to add the files in the submodule to the HEAD and remove the submodule. But then again it might not work because you don't really have a submodule.

Note that there is a trailing slash after the path. If you put this git removes the submodule and puts it into the HEAD, unlike:

git add lib/generators/haml

which will just change the commit to be checked out from the submodule in git submodules.

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