ide*_*ide 11 git git-submodules
我正在编写一个服务来更新超级项目中每个子模块指向的提交.我这样做的天真方式是git fetch在子模块中运行git reset --hard <hash>,然后添加子模块并提交它.
我想跳过这git fetch一步,简单地强制子模块指向给定的哈希以获得更好的性能(跳过获取对象并占用磁盘空间)并处理上游可能不再存在且无论如何都无法获取的提交(如果他们被强制推动破坏了.
ide*_*ide 13
解决方案是直接写入Git索引,这对于子模块来说实际上很简单.使用Git 2:
git update-index --cacheinfo 160000,<Git hash of the submodule's tree>,<path to the submodule>
例如,如果您的项目目录结构如下所示:
.
??? .git
??? submodule
Run Code Online (Sandbox Code Playgroud)
然后更新子模块以指向提交2764a900748fbed7453f5839cb983503cee346d2您将运行:
git update-index --cacheinfo 160000,2764a900748fbed7453f5839cb983503cee346d1,submodule
最后git commit像往常一样跟进.
| 归档时间: |
|
| 查看次数: |
1475 次 |
| 最近记录: |