Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 如何在保持浅子模块的同时丢弃浅子模块中的提交?_Git_Git Submodules - Fatal编程技术网

Git 如何在保持浅子模块的同时丢弃浅子模块中的提交?

Git 如何在保持浅子模块的同时丢弃浅子模块中的提交?,git,git-submodules,Git,Git Submodules,如果我有一个带有提交历史记录的repolib: * commit-4 * commit-3 * commit-2 * commit-1 我将它添加到我的repo-other-repoapp中,作为一个浅层子模块,app/.git/module/lib/shall=sha1(commit-4)。我可以将提交添加到lib,将其拉入子模块,然后将提交添加到app,以期望新的提交(例如,commit-5)。当我在别处克隆app时,app/.git/module/lib/shall现在是commit-5

如果我有一个带有提交历史记录的repo
lib

* commit-4
* commit-3
* commit-2
* commit-1
我将它添加到我的repo-other-repo
app
中,作为一个浅层子模块,
app/.git/module/lib/shall=sha1(commit-4)
。我可以将提交添加到
lib
,将其拉入子模块,然后将提交添加到
app
,以期望新的提交(例如,
commit-5
)。当我在别处克隆
app
时,
app/.git/module/lib/shall
现在是
commit-5
(运行
git子模块更新--init
)。一切正常

但是,如果我将提交添加到
app
而不是指向
lib
commit-3
(在子模块中使用
git pull--depth=2&&git reset--hard HEAD~
),当我转到克隆
app
其他地方时,
app/.git/module/lib/shall
不会更新。它保持在
commit-4
。但是,
app
仍然签出
commit-3
。由于
commit-3
不在以
commit-4
为根的浅层克隆中,git被迫对整个repo进行正常克隆,因此我失去了浅层克隆的好处

基本上,git似乎正在使用它在分支历史中可以找到的最新的浅“根”,除了这个,我什么都不允许使用

这是故意的行为吗?为什么?我应该如何丢弃浅子模块中的提交

我可以重新设置基址,但我想知道是否有非破坏性选项可用