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
I found this thread Unable to track files within Git submodules 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....
A nested repo is by default untracked.
(actually it tracks the submodule root folder as a gitlink, special entry in the index)
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:
git rm --cached mysubmodule
.mysubmodule
represents the gitlink, while mysubmodule/
is the folder created by the checked out submodule.git add mysubmodule
(here, you can add or not a trailing slash, it does not matter)mysubmodule
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With