一个 git 子模块如何添加特定提交并将其记录在 .modules 文件中?

2024-02-12

理想情况下我想要.modules文件具有我想要使用的确切提交并且不更改它(除非我告诉它,例如使用git submodule --init <path2submodule_repo> --remote)。但是 git 子模块添加注释似乎没有提供选项(所以我假设 .gitmodules 不能做到这一点?)请参阅手册页:

NAME
       git-submodule - Initialize, update or inspect submodules

SYNOPSIS
       git submodule [--quiet] [--cached]
       git submodule [--quiet] add [<options>] [--] <repository> [<path>]
       git submodule [--quiet] status [--cached] [--recursive] [--] [<path>...]
       git submodule [--quiet] init [--] [<path>...]
       git submodule [--quiet] deinit [-f|--force] (--all|[--] <path>...)
       git submodule [--quiet] update [<options>] [--] [<path>...]
       git submodule [--quiet] set-branch [<options>] [--] <path>
       git submodule [--quiet] set-url [--] <path> <newurl>
       git submodule [--quiet] summary [<options>] [--] [<path>...]
       git submodule [--quiet] foreach [--recursive] <command>
       git submodule [--quiet] sync [--recursive] [--] [<path>...]
       git submodule [--quiet] absorbgitdirs [--] [<path>...]

DESCRIPTION
       Inspects, updates and manages submodules.

       For more information about submodules, see gitsubmodules(7).

COMMANDS
       With no arguments, shows the status of existing submodules. Several subcommands are available to perform operations on the submodules.

       add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--depth <depth>] [--] <repository> [<path>]
           Add the given repository as a submodule at the given path to the changeset to be committed next to the current project: the current
           project is termed the "superproject".

           <repository> is the URL of the new submodule’s origin repository. This may be either an absolute URL, or (if it begins with ./ or ../),
           the location relative to the superproject’s default remote repository (Please note that to specify a repository foo.git which is located
           right next to a superproject bar.git, you’ll have to use ../foo.git instead of ./foo.git - as one might expect when following the rules
           for relative URLs - because the evaluation of relative URLs in Git is identical to that of relative directories).

           The default remote is the remote of the remote-tracking branch of the current branch. If no such remote-tracking branch exists or the
           HEAD is detached, "origin" is assumed to be the default remote. If the superproject doesn’t have a default remote configured the
           superproject is its own authoritative upstream and the current working directory is used instead.

           The optional argument <path> is the relative location for the cloned submodule to exist in the superproject. If <path> is not given, the
           canonical part of the source repository is used ("repo" for "/path/to/repo.git" and "foo" for "host.xz:foo/.git"). If <path> exists and
           is already a valid Git repository, then it is staged for commit without cloning. The <path> is also used as the submodule’s logical name
           in its configuration entries unless --name is used to specify a logical name.

           The given URL is recorded into .gitmodules for use by subsequent users cloning the superproject. If the URL is given relative to the
           superproject’s repository, the presumption is the superproject and submodule repositories will be kept together in the same relative
           location, and only the superproject’s URL needs to be provided. git-submodule will correctly locate the submodule using the relative URL
           in .gitmodules.

因此,这是在 bash 脚本中手动记录提交的唯一方法,如下所示:

git submodule add -f --name coq-projects/metalib https://github.com/plclub/metalib.git coq-projects/metalib
git submodule foreach -q --recursive 'git switch $(git config -f $toplevel/.gitmodules submodule.$name.branch || echo master || echo main )'

但显然是经过编辑的,所以它可以与提交一起使用? 例如

git submodule add -f --name coq-projects/metalib https://github.com/plclub/metalib.git coq-projects/metalib
Run git submodule foreach git checkout <commit-hash> to change the checked-out commit in each submodule to the desired commit. Replace <commit-hash> with the hash of the desired commit.

在 URL 中指定提交不适用于 git submodule add

但如果你 git add 它,它确实有效(无论哪种方式,我想,我们在 url 中没有提交,因为无论如何它都会获取错误的提交) cd 并获取正确的提交:

(iit_synthesis) brando9~/proverbot9001 $ git submodule add -f --name coq-projects/metalib git+https://github.com/plclub/metalib.git#104fd9efbfd048b7df25dbac7b971f41e8e67897 coq-projects/metalib
Reactivating local git directory for submodule 'coq-projects/metalib'.

...

(iit_synthesis) brando9~/proverbot9001/coq-projects/metalib $ cd coq-projects/metalib
-bash: cd: coq-projects/metalib: No such file or directory
(iit_synthesis) brando9~/proverbot9001/coq-projects/metalib $ git checkout 104fd9efbfd048b7df25dbac7b971f41e8e67897
Note: switching to '104fd9efbfd048b7df25dbac7b971f41e8e67897'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 104fd9e Sync Makefile coq version with README/Docker
(iit_synthesis) brando9~/proverbot9001/coq-projects/metalib $ git status
HEAD detached at 104fd9e
nothing to commit, working tree clean

Git 子模块在 Git 存储库下进行跟踪,因此它包括处理其中的 Git 子项目提交。 只需进入子模块目录,签出您想要的任何分离的提交、修订或标记,然后再次转到主存储库根目录并执行 Git diff,它将显示子模块的提交哈希差异;提交该内容的描述如下:“更新 X 的子项目提交以标记 Y”。

之后,当您想要克隆您的存储库时,您将使用 recurse-submodules 标志递归克隆。

cd <Submodule path>
git checkout <hash/tag/branch/etc>
cd - 

git status
git add <Submodule>
git commit "Update Subproject Commit for X to tag Y"
git push

然后,克隆的时候,这样克隆:

git clone --recurse-submodules <my repo with Submodules>

希望能帮助到你。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

一个 git 子模块如何添加特定提交并将其记录在 .modules 文件中? 的相关文章

  • `git ls-files -s` 输出中不同字段的含义是什么?

    在 Git 中 命令返回的典型结果行git ls files s好像 100755 be2c2e9b0966253096472d4b482c458bc892e493 0 gitignore 这些字段是什么意思 不用再犹豫了git ls fi
  • 格里特:! [远程拒绝] HEAD -> refs/publish/master (没有新的更改)

    我做了一些更改 提交了它们并将分支推送到 Gerrit git push gerrit 现在我的更改没有出现在 Gerrit 中 我认为这是因为我手动推送更改而不是使用git 审查 https github com openstack in
  • 第一次使用node.js - “ReferenceError:节点未定义”

    我刚刚安装了node js 我尝试编写应该检查版本的node v 但它不起作用 这是输出 gt node v ReferenceError node is not defined at repl 1 2 at REPLServer self
  • Ansible bitbucket 克隆存储库配置 ssh 错误

    我之前发布过这个问题 但那里的答案不再有效 总之 当使用 Ansible 配置我的 vagrant box 时 在尝试使用 ssh 克隆我的 bitbucket 私有存储库时 我遇到了一个神秘的错误 该错误指出 权限被拒绝 公钥 然而 如果
  • Netbeans 和 Git,.obj 文件被忽略

    我正在开发一个涉及 obj 文件的小型 git 项目 当我查看 项目选项卡 时 我发现它们被忽略了 但如果我查看我的 gitignore 我无法理解为什么 DepthPeeling nbproject private DepthPeelin
  • apt-get 无法在 ubuntu dockerfile 中工作

    我对 docker 相当陌生 正在尝试通过编写自己的镜像来学习 并且目前正在阅读 Docker 的实际操作 ISBN 1633430235 在我自己的代码和书中的示例 第 146 页 中 我想通过 dockerfile 安装 git My
  • git 日志历史记录图,每次提交一行,彩色,带有日期

    我需要的格式如下 git log decorate graph oneline date order 但我也需要它 包含日期 短 具有相同的颜色 I tried git log decorate graph oneline date ord
  • 如何在 macOS 上将 Git 升级到最新版本?

    我刚刚购买了一台装有 OS X Lion 的新 Mac 我在终端中检查了默认安装的 git 版本 我得到了答案 git version gt git version 1 7 5 4 我想将 git 升级到最新版本 1 7 8 3 因此我下载
  • Git 2.2.x 无缘无故更新旧包文件的时间戳

    Git 2 2 0 和 2 2 1 似乎修改了旧的时间戳 git objects pack pack pack偶尔会无缘无故地文件 它只是改变时间戳 内容是相同的 调试这一点很困难 因为它似乎很少进行更改 我在 2 2 0 之前的任何 Gi
  • 为所有子文件夹设置 git 配置值

    我知道可以设置每个存储库的配置来覆盖用户级配置 即 path to my repo gitconfig覆盖 gitconfig 是否可以设置 git 配置来覆盖给定文件夹的所有子文件夹的用户级设置 即 我有 topLevelFolder1
  • 为什么 Git 无法将文件更改与修改后的父级/主控合并?

    我有一个文件 里面只有一行 我创建一个分支并向同一文件添加第二行 保存并提交到分支 我切换回主人 并向文件中添加不同的第二行 保存并提交给master 现在总共有 3 条独特的线路 如果我现在尝试将分支合并回主分支 则会遇到合并冲突 为什么
  • 使当前提交成为 Git 存储库中唯一(初始)提交?

    我目前有一个本地 Git 存储库 我将其推送到 Github 存储库 本地存储库有约 10 次提交 Github 存储库是其同步副本 我想要做的是从本地 Git 存储库中删除所有版本历史记录 以便存储库的当前内容显示为唯一提交 因此存储库中
  • 仅使用 Git grep 的文件名

    我只想查看文本中包含特定单词的不同文件 current directory git grep word 显示文件中具有匹配单词的每一行 所以我尝试了这个 current directory git grep word files with
  • `git push` -- 没有输出,什么也没有发生

    touch test git add test git commit m test git push u origin master 这奏效了 该文件已上传到存储库 rm test cp R website website git rm t
  • VSTS:在构建过期的情况下自动变基/合并和重新排队构建验证门

    我们最近对 PR 上的构建验证门进行了更改 这样 如果另一个提交在当前 PR 完成之前进入主分支 则构建会 立即 过期 看here https stackoverflow com questions 49418800 vsts invali
  • git merge 冲突的不同场景

    我试图了解 git 合并后可能发生 git 冲突的情况以及如何避免它们 我创建了一个 git 存储库并向其中添加了一个文本文件 我已将 1 添加到文本文件中并将其提交给 master 我已经从 master 创建了一个新分支 分支 2 并将
  • 有没有一个简单的命令可以将分支转换为标签?

    我即将完成将 哑快照 转换为 git 的繁琐过程 这个过程进展得非常顺利 感谢这个重命名过程 https stackoverflow com questions 6628539 how to tell git that its the sa
  • Gerrit 和 Active Directory

    我正在尝试设置 Gerrit 以使用我们的公司 Active Directory 进行身份验证 我知道很多人都设法让它发挥作用 但它对我来说不起作用 如果我运行一个ldapsearch命令如下我得到了正确的结果 所以我知道我的搜索字符串是正
  • 是否可以检测 http git 远程是智能还是愚蠢?

    我正在我的应用程序中实现一个选项来使用 depth 1制作 git repo 的最小功能克隆 我刚刚意识到愚蠢的 http 传输不支持 depth 我想自动检测 http 远程是愚蠢的还是聪明的 这样我就可以省略 depth与哑 http
  • GIT:提交时“致命:无法写入 new_index 文件”

    当我尝试将更改提交到本地存储库时 我收到以下消息 致命 无法写入 new index 文件 As this 线程说明 http luhman org blog 2010 04 05 git fatal unable write newind

随机推荐

  • 与 Flexbox 底部对齐

    我的容器应该根据内容动态改变高度 对于给定行中的所有容器 底部文本都应固定在底部 无论每个容器中的内容如何 flex list display flex flex direction column flex list flex row di
  • google api 错误 - 无法让 google 登录正常工作

    我有一个应用程序需要访问 Google Fit Api 我可以弹出谷歌登录窗口 但下一个屏幕 请求我的数据类型 TYPE STEP COUNT DELTA AGGREGATE STEP COUNT DELTA 权限的屏幕不会显示 一旦我选择
  • 为什么当我想使用 EF Power 工具查看我的模型时出现错误?

    我首先使用 EF Code 然后通过 vs2010 中的 EF 4 x DbContext Fluent Generator for c 扩展生成我的模型 但是当我想通过 EF Power 工具查看我的实体模型时 我收到此错误 序列不包含匹
  • C++ 不同类型模板化类的显式模板化函数实例化

    我正在尝试在类型 T 的模板化类中显式实例化类型 U 的模板化函数 下面的代码生成警告 并且链接器找不到显式实例化ReinterpretAs 任何人都可以发现错误或建议如何执行此操作吗 我使用的是VC 2010 template
  • Bootstrap:在模式对话框中,如何使下拉菜单扩展到对话框之外?

    示例代码 http jsfiddle net vpg5g http jsfiddle net vpg5g 我想让从按钮下拉的菜单扩展到模式的边框上 如您所见 当前状态无法使用 有什么方法可以实现这一目标吗 模式不允许任何溢出 您可以使用以下
  • document.getElementsByTagName 在 vbscript 中工作吗?

    嗯 它有效 只是没有产生任何有价值的东西 elems document getElementById itemsTable getElementsByTagName TR for j 0 to ubound elems 1 stuff ne
  • 如何直接从内存中显示 webBrowser 控件中的图像?

    如何直接从内存而不是硬盘在 webBrowser 控件中显示图像 当我使用 RAM Disk 软件创建虚拟驱动器时 可以寻址图像源来加载它 如下所示 img src Z image jpg 表示 Z 是 RAM 磁盘驱动器 是否可以在 NE
  • css 中 ?v=2 是什么意思? [复制]

    这个问题在这里已经有答案了 可能的重复 将 v 1 附加到链接和脚本标记中的 CSS 和 Javascript URL 有何作用 https stackoverflow com questions 3466989 what does app
  • Admob插页式显示黑屏

    最近 我在使用 admob 显示插页式广告时遇到黑屏 这就是我正在谈论的屏幕 有时它运行良好并正确显示广告 这是我使用的代码 Class variable private InterstitialAd oInterstitialAd nul
  • 为什么 sleep 函数睡眠不一致?

    import time from time import sleep from datetime import datetime while True print datetime now strftime Y m d H M S slee
  • C# 属性覆盖Set方法

    我有一个如下所示的班级 当有人设置值时 我想覆盖 学校 国家 等 属性的设置值 我不想更改学生班级 但我需要这样做在基类中并将其用作通用方法 public class Student BaseClass public String Scho
  • 使用 rCharts 添加到图表中所有数据点的唯一链接

    我正在使用 rCharts 创建一个散点图 显示我随时间计算的评分 我有每个单独数据点 评级 的更多信息 并且希望图表上的每个数据点链接到一个独特的页面 其中包含有关该特定数据点的更多信息 例如 我希望能够将鼠标悬停在图表上的第一个数据点上
  • 如何在 Youtube Android Player API 中启用纸板模式?

    我想在我的应用程序中以纸板模式观看 Youtube 的 360 度视频 该模式将视频分成两半 供 Google 纸板中的两个镜头使用 就像在 Youtube 应用程序中一样 我正在使用适用于 Android 的 Youtube 播放器 AP
  • Android Studio渲染问题

    我在用着安卓工作室0 2 3当打开一个活动布置通常 预览应该出现在右侧 以便我可以在之间切换Text and Design模式 这应该再次显示布局的预览 但当我进入时 右侧也没有显示预览text模式也不在design模式 我刚刚收到错误re
  • JMeter在HTTP请求中使用beanshell变量

    我是这里的绝对菜鸟 我的意思是JAVA 花了几个小时寻找解决方案 现在我只想开枪自己 我想在 beanshell 断言中创建一个字符串 该字符串位于 HTTP 请求的正上方 在 beanshell 中我写道 String docid abc
  • 如何在 Mysql 中使用带有 BETWEEN 子句的字母数字字段?

    我有一个包含字段名称为 mgrs 的表 存储在 mgrs 字段中的值类似于 42SWC227821555 可能包含更多字符 并且可能包含小写字母 现在我想搜索两个经理之间的记录 那么我该怎么做呢 我可以先将 mgrs 值转换为整数 然后在
  • 从 Matlab 创建的 jar 文件返回值

    我有一个 Matlab 代码 它最终计算出索引向量 我使用库编译器将 matlab 代码编译为 java 包 jar 文件 我导出了 jar 文件以便在我的主 Java 项目中运行它 包类的名称是 Epidemic 我导入了 jar 文件
  • 无法连接到 BLE 设备

    尝试将 Android 手机连接到某种不寻常的非标准 BLE 设备 血压监测仪 数据点 我的程序可以正常连接并读取其他 BLE 设备 我的程序在 BLE 扫描中看到设备 但无法连接 相反 我立即获得 已断开连接 状态 并带有通用 GATT
  • attributeSubstringFromRange 越界问题

    我有一个 NSMutableAttributedString 我需要从中获取子字符串 我使用以下代码来获取子字符串 startIndex 和 endIndex 是两个长变量 NSMutableAttributedString current
  • 一个 git 子模块如何添加特定提交并将其记录在 .modules 文件中?

    理想情况下我想要 modules文件具有我想要使用的确切提交并且不更改它 除非我告诉它 例如使用git submodule init