了解 git 子模块并在特定的提交哈希或版本中“冻结”它
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7238426/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Understanding git submodule and "freezing" it at a specific commit hash or version
提问by Calvin Cheng
Assuming the following project layout:-
假设以下项目布局:-
mainrepo_git
|____ .git
|____ .gitmodules
|____ proj <------- directory containing the code files for mainrepo
|____ 3rdpartysourcecode <-- directory containing upstream open source code
| |____ .git
| |____ 3rdpartyfiles
|
|____ mainrepofilesanddirectories
mainrepo_gitcontains 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包含我直接负责的源代码。我有读/写访问权限,可以直接推送和拉取到我管理的远程 git 存储库。
Nested inside mainrepo_gitis a directory which I named 3rdpartysourcecode. This 3rdpartysourcecodedirectory 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.
嵌套在mainrepo_git 中的是一个我命名为3rdpartysourcecode的目录。这个3rdpartysourcecode目录实际上是另一个 git 存储库(通常也称为“git 子模块”),它指向一个由其他开发人员管理的开源 3rd 方 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?
有什么方法可以“冻结”与在我的主存储库中进行的提交相关的 git 子模块的特定提交哈希?
For example, if I am at (or I revert to) commit a12ucakin 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?
例如,如果我在(或恢复到)在我的 mainrepo 中提交a12ucak,我的 git 子模块也会恢复到我绑定到提交a12ucak的特定版本?当我切换到提交b349jdsak 时,我的 git 子模块也会恢复到我绑定到b349jdsak的版本?
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 子模块中的相应提交之间创建链接?这样,当我在主 git repo 中检出该特定提交时,git 子模块中的相应提交也将被检出。
采纳答案by Karl Bielefeldt
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 add 3rdpartysourcecode
(重要的是没有尾部斜杠!)后跟一个提交将当前检出的子模块提交锁定到超级模块提交。然后你用它git submodule update
来检查那个修订版。