简体   繁体   中英

How to make top-level git to track all the files under another sub-directory git

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 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:

  • remove the gitlink: git rm --cached mysubmodule .
    Note the lack of trailing slash: mysubmodule represents the gitlink, while mysubmodule/ is the folder created by the checked out submodule.
  • add it back to the index of the parent repo: git add mysubmodule (here, you can add or not a trailing slash, it does not matter)
  • commit the new files added and present in mysubmodule .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM