views:

68

answers:

1

command sequence

mkdir topdir
mkdir another-git-directory
touch fileC
touch fileD
git add .
git commit -m "sub-dir init"
cd ..
touch fileA
touch fileB
git add .
git commit -m "top-dir init"
git ls-files
// now we can see that fileC and fileD is not tracked by top-level git //
git ls-files -o
// this would not show us the fileC and fileD as untracked files//

my question is: how can we make "git ls-files -o" to show the untracked files inside sub-directory? why git is behaved such, as i expect git ls-files to show all untracked file (even it is inside another sub-dir git)?

I know that I could make the top git to track the sub-dir files using "git add */."... but I am interested to know why for the question above. Thanks!

directory structure

 topdir +  
        +-- .git  
        +-- fileA  
        +-- fileB  
        + another-git-directory +-- .git  
                                +-- fileC  
                                +-- fileD  

update (26 Jun)

I found this thread http://stackoverflow.com/questions/1084969/unable-to-track-files-in-deep-directories-by-git and this url (cn) http://blog.ossxp.com/2010/01/425/ which explains how to resolve the problem.

the solution:

git rm --cached another-git-directory #no trailing slash
git add another-git-directory/.
git commit

the 'git rm --cached path/to/sub-dir-or-sub-module' will tell the top-dir not to treat the sub-dir as a submodule... I think....

+1  A: 

A nested repo is by default untrancked.
Git will detect the nested .git repo, and the parent repo will delegate any file status to the nested one.

To show them tracked, you may have to:

  • init another-git-directory elsewhere (i.e. outside 'topdir'),
  • declare another-git-directory within topdir as a submodule
    (recreating the directory structure you mention in your question),
  • use git 1.7+ which have enhanced git status able to show the status of the current repo and any nested submodules within said current repo
VonC
Thanks Vonc. There is constraints as the sub-dir git is not created by me so first approach is out. For the submodule, as I read from your link, it doesn't seems to do what I want, as I want to generate the diff for files in all sub-dir(s) from the top-dir. I have updated git 1.7.1 and try "git status -u all" but still it doesn't show the untracked fileC and fileD
insidepower
@insidepower: strange, that notion should be available: just clone that nested repo elsewhere, then delete it, and recreate it as a submodule. Then the git status will show any modification for C and D (only if you modify them of course)
VonC
okay, i set the submodulesummary to true using "git config status.submodulesummary true" and it now spit out the submodules changes. but it does not tell which files have changes, just the summary of it. e.g. modified: sub-dir2 (modified content)btw, the 'git status' in 1.7.1 is very very very slow on large project. I am going to change back.... sigh
insidepower
@insidepower: strange (bis) Are you using a msysgit Windows distribution for git? Note: You can also try `git config status.showUntrackedFiles no` to only stat files in your index. If you need to show untracked files at some point, you can always do: `git status -unormal`
VonC
@VonC: no I am using ubuntu, current built is 1.6.0.4 if i didn't remember wrongly. I have switched back to this version and the git status is back to normal rate. Sigh now I couldn't try the showUntrackedFiles option unless I switch back to 1.7.1 again. However I don't think I can tolerate the speed of its 'git status'... This is Life I guess :)
insidepower
@insidepower: I agree, `git status` is very slow from 1.7+: see http://longair.net/blog/2010/06/02/git-submodules-explained/ and http://lists-archives.org/git/719848-git-status-and-git-diff-now-very-slow-in-project-with-a-submodule.html
VonC