Tre*_*ham 14 git git-submodules
我在我的Rails 3项目中添加了一些Haml模板
git clone git://github.com/psynix/rails3_haml_scaffold_generator.git lib/generators/haml
Run Code Online (Sandbox Code Playgroud)
只是发现,当我尝试编辑其中一些文件时,这是一个子模块,所以我无法提交我在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")
Run Code Online (Sandbox Code Playgroud)
但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
Run Code Online (Sandbox Code Playgroud)
额外的git adds是没用的.如果我尝试git rm -rf lib/generators/haml,我会
fatal: git rm: 'lib/generators/haml': Operation not permitted
Run Code Online (Sandbox Code Playgroud)
它不会死!我已经查找了如何删除子模块,但在这种情况下,没有.submodules文件,也没有提到子模块.git/config.然而,如果我跑git submodule update,我会
No submodule mapping found in .gitmodules for path 'lib/generators/haml'
Run Code Online (Sandbox Code Playgroud)
我删除了目录,但得到了相同的结果!这是怎么回事?我是否需要创建一个.gitmodules文件来删除子模块?
如果子模块有未跟踪的文件,则子模块在git状态下显示为已修改.如果你调用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
Run Code Online (Sandbox Code Playgroud)
这意味着在这个子模块中有一些未跟踪的文件.它们不能通过父项目中的命令添加; 相反,你应该遍历到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)
Run Code Online (Sandbox Code Playgroud)
如果没有子模块,它是否可能(即' haml')实际上不是子模块?
git clone git://github.com/psynix/rails3_haml_scaffold_generator.git lib/generators/haml
Run Code Online (Sandbox Code Playgroud)
意思是:创建lib/generators/haml目录,并在其中签出主分支git://github.com/psynix/rails3_haml_scaffold_generator.git.
事实上你不能git status从新的repo(lib/generators/haml)的根目录开始,但是上面的三个级别(在哪里lib)意味着你在一个仓库中克隆了一个repo.
两个repo都可以独立工作,但你应该添加 lib/generators/haml到.gitignore父repo中(比如命中SO问题).