假设我具有以下结构:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tbody>
<tr>
<td><div class="test"></div></td>
</tr>
</tbody>
</table>
我在 .gitignore 文件中包含了 modules 目录,并为 my-third-module 设置了一个例外:
my-project
├── modules
│ ├── my-first-module
│ ├── my-second-module
│ └── my-fourth-module
然后,当我从 my-project / modules / 路径执行/my-project/modules/*
!/my-project/modules/my-third-module/
时,我得到:
git submodule add git@git.my-app/my-third-module.git
似乎没有考虑在 .gitignore 中排除The following path is ignored by one of your .gitignore files:
my-project/modules/my-third-module
Use -f if you really want to add it.
。
因此,我尝试创建一个空的 my-third-module 目录,但在这种情况下,/my-project/modules/my-third-module/
命令会抱怨:
git submodule add
显然,'my-third-module' already exists and is not a valid git repo
要求该目录不存在,所以这不是可行的方法。
为什么Git不考虑排除 my-third-module ?
答案 0 :(得分:0)
如this answer中所述:
除非指定了
git submodule add
,否则--force
会通过调用submodule add
来检查目标路径是否被忽略
因此,我执行了git add --dry-run --ignore-missing
并且得到了:
git add --dry-run --ignore-missing my-third-module
这使我怀疑在 .gitignore 中排除一个不存在的目录可能存在问题。
我手动创建了我的第三模块后,再次执行了The following paths are ignored by one of your .gitignore files:
my-project/modules/my-third-module
Use -f if you really want to add them.
命令,现在可以了。
这意味着Git需要创建目录才能排除它。但是自创建以来,它就被排除在外了。
命令git add
根本不会自动负责。
因此,在这种情况下使用git submodule add
可以安全地添加子模块:
-f
my-third-module 目录将在创建后被Git完全忽略。