我怎样才能设置一个子模块来指向特定的提交而不用提取? [英] How can I set a submodule to point to a specific commit without fetching it?

查看:110
本文介绍了我怎样才能设置一个子模块来指向特定的提交而不用提取?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个更新超级项目中每个子模块所指向的提交的服务。我这样做的简单的方式。将运行 GIT中取在一个子模块, GIT中的复位 - 硬<散列> ,然后添加子模块并提交它。



我想跳过 git fetch 步骤强制子模块指向给定的散列以获得更好的性能(跳过获取对象并占用磁盘空间),并处理可能不再存在于上游并且无法被提取的提交(如果它们被强制推送所破坏) 。解决方案是直接写入Git索引,对于子模块来说实际上很简单。 在GIT 2:



GIT中更新索引--cacheinfo 160000,<第子模块的树>的GIT中散列;,<路径子模块> ;






例如,如果您的项目目录结构如下所示:

 
├──.git
└──子模块

然后更新子模块指向承诺你将运行2764a900748fbed7453f5839cb983503cee346d2:



的git更新指数--cacheinfo 160000,2764a900748fbed7453f5839cb983503cee346d1,子模块



最后按照惯例继续使用 git commit

I am writing a service that updates the commit that each submodule in a superproject points to. My naive way of doing this would be to run git fetch in a submodule, git reset --hard <hash>, and then add the submodule and commit it.

I would like to skip the git fetch step and simply force the submodule to point to a given hash for better performance (skip fetching the objects and taking up disk space) and to handle commits that may no longer exist upstream and can't be fetched anyway (if they were clobbered by a force push).

解决方案

The solution is to write to the Git index directly, which actually is simple for submodules. With Git 2:

git update-index --cacheinfo 160000,<Git hash of the submodule's tree>,<path to the submodule>


So for example if your project directory structure looks like this:

.
├── .git
└── submodule

Then to update the submodule to point to commit 2764a900748fbed7453f5839cb983503cee346d2 you would run:

git update-index --cacheinfo 160000,2764a900748fbed7453f5839cb983503cee346d1,submodule

And finally follow it up with git commit as usual.

这篇关于我怎样才能设置一个子模块来指向特定的提交而不用提取?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆