我在我的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
文件才能删除子模块吗?
lib/generators/haml
中的内容时,我应该进入该目录,然后进行git操作。正如你建议的那样,我将我的git从1.7.0.5更新到了1.7.2,这确实给了我更有用的消息。仍然让我感到困惑的是,即使我删除了lib/generators/haml
及其.git
目录,git仍然认为存在一个子模块。 - Trevor Burnham