51

Problem: to add files at ./shells/smallApps/* to Git at ./.git/ when I do not have the files at ./.git/info/exclude nor at any .gitignore -files.

This question is based on this tread where the problem is not solved completely.

I run

$git status                                                                                                                                          ~/bin
# On branch master
nothing to commit (working directory clean)
$git ls-files                                                                                                                                        ~/bin
Screen/dev/vim-open.screen
--- cut ---

I note that I do not have the files "shells/smallApps/*" at my Git

$ls shells/smallApps/                                                                                                                                ~/bin
devTodo     extract     
                                                                                                                                             ~/bin

I want to add them to my Git by running

$git add shells/smallApps/devTodo shells/smallApps/extract
fatal: Path 'shells/smallApps/devTodo' is in submodule 'shells/smallApps'
$git add .         

I note that the files are not added to my Git for some reason such that

$git status                                                                                                                                          ~/bin 
# On branch master
nothing to commit (working directory clean)

I do not have the files at .git/info/exclude nor at .gitignore -files.

What does the last warning mean?

Community
  • 1
  • 1
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697

3 Answers3

103

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:

  1. The file matches a pattern $GIT_DIR/exclude.
  2. The file matches a pattern in a .gitignore file inside the repo.
  3. The file matches a pattern in a user-specific .gitignore file (specified by 'git config --global core.excludesfile').
  4. 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:

  1. The .gitmodules file in your main repo.
  2. An entry in the .git/config of your main repo.
  3. 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.

  1. Delete the relevant line from the .gitmodules file.
  2. Delete the relevant section from .git/config.
  3. Run git rm --cached path_to_submodule (no trailing slash).
  4. 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:

  1. cd path_to_submodule
  2. rm .git
  3. cd ..
  4. git add path_to_submodule
  5. git status
  6. 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 in editors/vim/vimdoclet
  • No .git directory in shells/smallApps
Community
  • 1
  • 1
Tim Henigan
  • 60,452
  • 11
  • 85
  • 78
  • I run `find ./ -iname .gitmodules` at ~/bin and at HOME unsuccessfully: no .gitmodules -file. -- I am not sure where the problem is exactly. – Léo Léopold Hertz 준영 Jul 08 '09 at 17:43
  • I have no mention of submodules at my `~/.git/config` nor at `~/bin/.git/config` – Léo Léopold Hertz 준영 Jul 08 '09 at 17:44
  • Two questions then: 1. Is the '~' in the above comment your home directory or the root directory of the repo? 2. How was this submodule created? Did you copy the submodule files from another location or was it created via a git submodule add command? – Tim Henigan Jul 08 '09 at 18:24
  • Also, what version of Git are you using? – Tim Henigan Jul 08 '09 at 18:26
  • After attempting the sequence outlined above, I found a caveat to the GitWiki entry. If after removing the submodule you want to keep the cached files that were left, you must manually remove the `.git` directory from the submodule. The instructions have been modified to show this. – Tim Henigan Jul 08 '09 at 19:19
  • @Tim: ~ is my HOME. For instance ~/bin is HOME/bin. --- I did not create any submodule by myself consciously. I have never run `git submodule add` or any `submodule` command by myself. --- The only outside-code is Vimdoclet at HOME/bin/ (dpaste above) at the two PATHs. Besides that I once run `git init` at HOME/bin/shells/smallApps/. --- My Git is 1.6.3.1. – Léo Léopold Hertz 준영 Jul 08 '09 at 20:18
  • @Tim: How can I know which is the submodule -folder? – Léo Léopold Hertz 준영 Jul 08 '09 at 20:21
  • 1
    @Masi: Based on your dpaste link, you have 2 submodules inside your main repo. The submodule folders are `editors/vim/vimdoclet` and `shells/smallApps`. If you want to eliminate both submodules, you need to execute my instructions twice. Once for each submodule folder. You must substitute the submodule folder names for the `path_to_submodule` in my instructions. – Tim Henigan Jul 08 '09 at 21:27
  • @Masi: Please note that the `.gitmodules` and `.git/config` files that I mentioned in my instructions should be found in the same directory that you executed your dpaste command (`find . -name .git`). – Tim Henigan Jul 08 '09 at 21:29
  • @Tim: I do not have .gitsubmodules -file. My .git/config -file is http://dpaste.com/65070/ – Léo Léopold Hertz 준영 Jul 09 '09 at 15:23
  • @Tim: Thank you for the update! --- I get `No submodule mapping found in .gitmodules for path` after running at ~/bin `git submodule status` – Léo Léopold Hertz 준영 Jul 12 '09 at 14:32
  • 3
    @Tim: I got the problem solved by running at ~/bin: `git rm --cached shells/smallApps` --- Thank you for the link! – Léo Léopold Hertz 준영 Jul 12 '09 at 14:50
  • Thanks. The submodule on my project is untracked so I went inside the submodule directory through command 'cd' and checked 'git status' there. Then I added the file through 'git add'. Thanks a lot. :D – KarenAnne Jun 26 '13 at 04:10
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.

Greg Hewgill
  • 951,095
  • 183
  • 1,149
  • 1,285
2

You should consider posting this question to the Git mail list (git@vger.kernel.org). 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
Tim Henigan
  • 60,452
  • 11
  • 85
  • 78