有没有办法在项目标签中包含特定版本的git子模块? [英] Is there a way to include a particular version of a git submodule in a project tag?

查看:134
本文介绍了有没有办法在项目标签中包含特定版本的git子模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目SubProj,我想在MainProj中包含一个子模块。但是,我想确保任何版本的MainProj都包含特定版本的SubProj以确保满足所有依赖。



换句话说,当我标记MainProj作为新版本V1.0的特别提交,我也想包括例如SubProj V1.3,以便每当有人检出MainProj 1.0时,子模块将始终初始化为V1.3,而不是SubProj HEAD当时指向的任何提交。



<这可能吗?

解决方案

我不认为你需要做额外的事情。 b

git-submodules的哲学是将子模块的特定commit sha值存储在主repo的任何状态中。这就是说,我的下面的命令将清楚地表明我们不需要做任何额外的事情。



让我们找到当前的子模块提交id

  $ cd< sub-module-directory> 
$ git rev-parse HEAD#当前最新的头像,我们假设它是`05a6fa8abb96fddf8c44cdf2a07cfbf1c7f8c268`

让我们来看一下主要的回购版本

  $ cd main-repo-directory 
$ git log #Pick any先前从列表中提交sha-id,说< main-prev-commit-sha>
$ git reset --hard< main-prev-commit-sha>

让我们删除子模块并重新更新它

  $ rm -rf< sub-module-directory> 
$ git submodule update

让我们找到新的submodule commit id

  $ cd< sub-module-directory> 
$ git rev-parse HEAD#新的最新的头像,让我们说它`ca3efe77286aa737d5b63747dfe9a6b6531e3bf3`

现在,我们发现submodules的commit sha对于主repo的不同版本是不同的。因此,恕我直言,当主要的回购标签是一个版本,然后隐式地,我们也冻结了子模块的sha-id那个时候。如果有人只是检查这个主要回购的旧版本,然后在子模块的初始化/更新,他会得到完全相同的内容,而不是子模块的最新状态。


I have a project SubProj, which I want to include as a submodule in MainProj. However, I want to make sure that any releases I do of MainProj also include a particular version of SubProj to ensure all dependencies are satisfied.

In other words, when I tag a particular commit of MainProj as a new version V1.0, I also want to include e.g. SubProj V1.3, so that whenever someone checks out MainProj 1.0 the submodule will always initialise to V1.3, rather than whatever commit in SubProj HEAD is pointing to at the time.

Is this possible?

解决方案

I do not think if you need to do anything extra.

The philosophy of git-submodules is storing the specific commit sha value of a submodule against any state of the main repo. That being said my below commands will make it clear that we do not need to do anything extra.

Let's find the current submodule commit id

$ cd <sub-module-directory>
$ git rev-parse HEAD # Current Latest Head, let's say it `05a6fa8abb96fddf8c44cdf2a07cfbf1c7f8c268`

Let's go to a previous version of main repo

$ cd main-repo-directory
$ git log #Pick any previous commit sha id from the list, say <main-prev-commit-sha>
$ git reset --hard <main-prev-commit-sha>

Let's remove the submodule and re-update it

$ rm -rf <sub-module-directory>
$ git submodule update

Let's find the new submodule commit id

$ cd <sub-module-directory>
$ git rev-parse HEAD # New Latest Head, let's say it `ca3efe77286aa737d5b63747dfe9a6b6531e3bf3`

Now as we found the commit sha for submodules is different for the different revisions of the main repo. whenever initialised/updated with a fresh checkout.

And hence, IMHO, when main repo is tagged with a version then implicitly we are also freezing the sha-id of the submodule of that time. And if somebody just check out this old version of the main repo then on init/update of the submodule he will get exactly the same content of that time, not the latest state of the submodule.

这篇关于有没有办法在项目标签中包含特定版本的git子模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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