track文件 什么是git_如何让顶级git跟踪另一个子目录git下的所有文件

bd96500e110b49cbb3cd949968f18be7.png

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值