了解git子模块和“冻结"操作.在特定的提交哈希或版本 [英] Understanding git submodule and "freezing" it at a specific commit hash or version
问题描述
假定以下项目布局:-
mainrepo_git
|____ .git
|____ .gitmodules
|____ proj <------- directory containing the code files for mainrepo
|____ 3rdpartysourcecode <-- directory containing upstream open source code
| |____ .git
| |____ 3rdpartyfiles
|
|____ mainrepofilesanddirectories
mainrepo_git 包含我直接负责的源代码.我具有读/写访问权限,可以直接将其推入并拉到我管理的远程git存储库中.
mainrepo_git contains source code I am directly responsible for. I have read/write access and can push and pull directly to a remote git repository which I manage.
嵌套在 mainrepo_git 中的是我命名为 3rdpartysourcecode 的目录.实际上,此 3rdpartysourcecode 目录是另一个git repo(也通常称为"git子模块"),它指向由其他开发人员管理的开源第三方git仓库.我只有它的读取权限.没有写访问权限.
Nested inside mainrepo_git is a directory which I named 3rdpartysourcecode. This 3rdpartysourcecode directory is in fact another git repo (also commonly referred to as a "git submodule") which is pointing to an open source 3rd party git repository managed by other developers. I only have read access to it. No write access.
相对于在主存储库中进行的提交,有什么办法可以冻结" git子模块的特定提交哈希?
Is there any way of 'freezing' a specific commit hash of the git submodule in relation to a commit made in my main repository?
例如,如果我在mainrepo中(或还原为)提交 a12ucak ,则我的git子模块也将还原为我用来提交 a12ucak 的特定版本. em>?当我切换到提交 b349jdsak 时,我的git子模块也恢复为我绑定到 b349jdsak 的版本?
For example, if I am at (or I revert to) commit a12ucak in my mainrepo, my git submodule also gets reverted to a specific version which I tie to commit a12ucak? And when I switch to commit b349jdsak, my git submodule also gets reverted to a version which I tie to b349jdsak?
所以我的问题是:有一种方法可以在主仓库中的特定提交与git子模块中的相应提交之间创建链接?这样,当我在主git repo中检出特定的提交时,git子模块中的相应提交也将检出.
So my question is: there is a way to create a linkage between a specific commit in the main repo with a corresponding commit in the git submodule? In such a way where when I checkout that specific commit in the main git repo, the corresponding commit in the git submodule will also be checkout.
推荐答案
冻结是子模块的重点.您应该真正阅读有关它的教程.简而言之,git add 3rdpartysourcecode
(重要的是不带斜杠!)后跟一个提交,将当前签出的子模块提交锁定为超级模块提交.然后,您稍后使用git submodule update
签出该修订版.
Freezing is the whole point of submodules. You should really read a tutorial on it. In a nutshell, git add 3rdpartysourcecode
(important no trailing slash!) followed by a commit locks the currently checked out submodule commit to the supermodule commit. Then later you use git submodule update
to check out that revision.
这篇关于了解git子模块和“冻结"操作.在特定的提交哈希或版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!