了解 git 子模块和“冻结”它位于特定的提交哈希或版本

发布于 2024-12-02 04:25:25 字数 1032 浏览 1 评论 0原文

假设以下项目布局:-

mainrepo_git
    |____ .git
    |____ .gitmodules
    |____ proj            <------- directory containing the code files for mainrepo
            |____ 3rdpartysourcecode <-- directory containing upstream open source code
            |      |____ .git
            |      |____ 3rdpartyfiles
            |
            |____ mainrepofilesanddirectories  

ma​​inrepo_git 包含我直接负责的源代码。我有读/写访问权限,可以直接推送和拉取我管理的远程 git 存储库。

嵌套在 ma​​inrepo_git 中的是一个我命名为 3rdpartysourcecode 的目录。这个 3rdpartysourcecode 目录实际上是另一个 git 存储库(通常也称为“git 子模块”),它指向由其他开发人员管理的开源第 3 方 git 存储库。我只有读取权限。没有写权限。

有什么方法可以“冻结”与我的主存储库中所做的提交相关的 git 子模块的特定提交哈希吗?

例如,如果我在主存储库中提交(或恢复)a12ucak,我的 git 子模块也会恢复到与提交a12ucak 相关的特定版本?当我切换到提交 b349jdsak 时,我的 git 子模块也会恢复到与 b349jdsak 绑定的版本?

所以我的问题是:有一种方法可以在主存储库中的特定提交与 git 子模块中的相应提交之间创建链接吗?这样,当我在主 git 存储库中签出特定提交时,git 子模块中相应的提交也将被签出。

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_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.

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.

Is there any way of 'freezing' a specific commit hash of the git submodule in relation to a commit made in my main repository?

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?

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨曦÷微暖 2024-12-09 04:25:25

冻结是子模块的全部要点。您确实应该阅读有关它的教程。简而言之,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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文