Unable to track files within Git submodules
Solution 1:
UPDATE
There are two general reasons why Git will ignore a file: gitignore
and submodules
.
To be more specific, the following conditions will cause Git to ignore a file when 'git add
' is invoked:
- The file matches a pattern
$GIT_DIR/exclude
. - The file matches a pattern in a
.gitignore
file inside the repo. - The file matches a pattern in a user-specific
.gitignore
file (specified by 'git config --global core.excludesfile
'). - The file is part of a submodule.
Forcing 'git add
' on an ignored file:
You can check to see if a particular file is ignored by invoking 'git add full/path/to/file
'.
The man page states that "If an ignored file is explicitly specified on the command line, the command will fail with a list of ignored files."
If the file is ignored, you can force it to be added with 'git add --force full/path/to/file
'.
Instructions to eliminate a submodule reference:
As noted in a previous answer, shells/smallApps
is a submodule in your repository.
If the file is part of a submodule, the situation is more complex. You cannot modify the contents of the submodule from within the main project.
If you want to eliminate the submodule reference and directly track the files in your main repo, there are several steps that must be performed. You cannot simply remove the ".git" directory from the submodule. There are three links between your main repository and the submodule:
- The
.gitmodules
file in your main repo. - An entry in the
.git/config
of your main repo. - Any commits related to the submodule in your main repo history.
Per this related SO question, you need to perform the following steps to completely remove the sub-module:
NOTE: If another branch depends on this submodule, then removing it can corrupt your repository! This is a dangerous operation...use with caution.
- Delete the relevant line from the
.gitmodules
file. - Delete the relevant section from
.git/config
. - Run
git rm --cached path_to_submodule
(no trailing slash). - Commit
The files that were part of the submodule are now untracked and you may decide to keep or delete them as desired (with the one caveat mentioned below).
If you don't need these files, you may simply delete them.
Caveat: If you want to keep these files (which you appear to want), you must manually remove the .git
directory from the submodule folder:
cd path_to_submodule
rm .git
cd ..
git add path_to_submodule
git status
git commit
UPDATE:
Request for further information:
To assist debugging this issue, please post the output of the following complete session of commands:
cd to the top-level directory in your repo
ls -al
cat .git/config
find . -name ".git*"
git status
git add editors
git add shells
git status
Based on the description of what you have done so far, I expect to see:
- No
.gitmodules
file anywhere - Only one
.git
directory (found at the root of your repo) - No
.git
directory ineditors/vim/vimdoclet
- No
.git
directory inshells/smallApps
Solution 2:
I see you've got git add
saying something about submodules. Do you have nested Git repositories? Do this:
$ find . -name .git
How many .git
directories are listed? If there is more than one, then you've got multiple nested repositories and that could be a cause of some of this confusion.
Solution 3:
You should consider posting this question to the Git mail list ([email protected]
). You will likely get a more prompt and complete response.
If you do decide to post there, be sure to include:
- A description of what you are trying to achieve.
- A description of the problem you have encountered.
- A complete session log showing:
- cd to the top-level directory in your repo
ls -al
cat .git/config
find . -name ".git*"
git status
git add editors
git add shells
git status