Reputation: 77416
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 add
s 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?
Upvotes: 14
Views: 9214
Reputation: 1172
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.
Upvotes: 0
Reputation: 1324228
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).
Upvotes: 6
Reputation: 99264
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)
Upvotes: 6