2010-07-24 108 views
13

我加了一些Haml的模板,我的Rails 3项目,无法摆脱git的子模块

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 s为无用。如果我尝试git rm -rf lib/generators/haml,我得到

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

它只是不会死!我查过了how to delete submodules,但在这种情况下,没有.submodules文件,也没有提及.git/config中的子模块。然而,如果我跑git submodule update,我得到

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

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

回答

6

如果没有子模块,是有可能它(即“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主分支。

,你可以从你的新的回购协议(lib/generators/haml)的根做了git status不大,但上述三个层级的事实(其中lib是)意味着你有一个回购中克隆回购。

这两个回购可以独立工作,但您应该将lib/generators/haml添加到父回购的.gitignore(如匹配SO question)。

+0

谢谢,将它添加到'.gitignore'是个好主意。 – 2010-07-25 18:17:23

+1

但这不会将新文件推入回购,FYI – andho 2011-04-11 14:59:32

+0

我的问题竟然是无关的,但这有助于。 – 2012-12-24 13:25:42

6

如果子模块具有未跟踪文件,则该子模块在git状态下显示为已修改。如果调用git diff lib/generators/haml,你会最likeyl看到这样的事情:

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 

这意味着该子模块里面是留下了一些未跟踪文件。它们不能通过父项目中的命令添加;相反,您应该遍历到su​​mbodule并添加它们(或将条目添加到.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) 
+0

好吧,我想我明白了:我应该进入'lib/generators/haml',然后在那里做任何改变的时候从那里做git东西。 正如你所建议的那样,我将git从1.7.0.5更新到了1.7.2,这确实给了我更多有用的信息。 我仍然觉得git认为有一个子模块,即使我用'.git'目录吹掉了'lib/generators/haml'allong。 – 2010-07-25 18:16:32

0

你也可以使用:

git add lib/generators/haml/ 

到辅助模块的文件添加到头部和删除的子模块。但是再次可能无法正常工作,因为您没有真正的子模块。

请注意,路径后面有斜线。如果你把这个混帐删除子模块,并把它入目,不像:

git add lib/generators/haml 

这将只是改变承诺将在git的子模块的子模块签出。