Git 子模块的 gitlink 条目位于哪里?

2024-10-25 08:42:00
admin
原创
232
摘要:问题描述:在哪里可以看到提到的 gitlink 条目gitsubmodules(7)?对于工作目录位于 的子模块path/to/bar/,gitlink 条目应位于/path/to/bar并包含子模块提交的 SHA-1 哈希值?$ git submodule status 139dedcb98fca8fb6...

问题描述:

在哪里可以看到提到的 gitlink 条目gitsubmodules(7)

对于工作目录位于 的子模块path/to/bar/,gitlink 条目应位于/path/to/bar并包含子模块提交的 SHA-1 哈希值?

$ git submodule status
 139dedcb98fca8fb69d70305709783ff40316cd4 tabulous (0.5.0-2-g139dedc)
 24afe922e6a05891756ecf331f39a1f6743d3d5a vim-repeat (v1.2-9-g24afe92)
 f51a26d3710629d031806305b6c8727189cd1935 vim-surround (v2.1-18-gf51a26d)
$ ls -la tabulous/
total 72
drwxr-xr-x  8 nlykkei  staff   256B Apr  5 17:25 ./
drwxr-xr-x  5 nlykkei  staff   160B Apr  4 12:00 ../
-rw-r--r--  1 nlykkei  staff    67B Apr  4 12:00 .git
-rw-r--r--  1 nlykkei  staff    21B Apr  4 12:00 .gitignore
-rw-r--r--  1 nlykkei  staff    18K Apr  4 12:00 LICENSE
-rw-r--r--  1 nlykkei  staff   5.0K Apr  5 17:25 README.md
drwxr-xr-x  4 nlykkei  staff   128B Apr  5 17:25 doc/
drwxr-xr-x  3 nlykkei  staff    96B Apr  5 17:25 plugin/
$ cat tabulous/.git
gitdir: ../../../../../.git/modules/vim/pack/bundle/start/tabulous

man 7 gitsubmodules

   ...
   Assuming the submodule has a Git directory at $GIT_DIR/modules/foo/ and a working directory at path/to/bar/, the superproject tracks the submodule via a gitlink entry in
   the tree at path/to/bar and an entry in its .gitmodules file (see gitmodules(5)) of the form submodule.foo.path = path/to/bar.

   The gitlink entry contains the object name of the commit that the superproject expects the submodule's working directory to be at.

解决方案 1:

Git 记录添加的子模块内容的提交 ID 的方式与记录添加的文件内容的 Blob ID 的方式相同,即在索引或记录树中列出的 ID。这是一个 gitlink:您的内容位于另一个提交中,您可以根据需要在该路径中签出。helpergit submodule命令可帮助您查找和处理包含该提交的存储库,但它只不过是助手,一个任意名称的杂锦包,用于方便的一到五行小代码,否则您最终会自己编写。

git rev-parse @:tabulous      # HEAD commit entry: "the current checkout had this here"
git rev-parse :tabulous       # index entry, "last thing added or checked out here"

git -C tabulous rev-parse HEAD   # what's actually checked out here

当然,你可以正常进行任何进一步的检查,跟踪内容的低级版本是

git -C tabulous diff-index --quiet --cached @ || echo staged changes in tabulous
git -C tabulous diff-files -q                 || echo unstaged changes in tabulous

我不知道如何通过一个命令快速检查“任何未跟踪的内容”,我认为你仍然需要 ls-files 和一些脚手架,例如

stdbuf -oL git -C tabulous git ls-files --exclude-standard -o  | grep -q . \n&& echo untracked, unignored files in tabulous

stdbuf -oL git -C tabulous git ls-files --exclude-standard -oi | grep -q . \n&& echo untracked, ignored files in tabulous

(该stdbuf -oL部分仅在真正大的工作树中才重要,在这种树中,值得进行按键以避免走太多路来找到充满名称的整个缓冲区)

请注意,各个目录作为对象存在于对象数据库中,但不存在于索引中,每次它们包含的任何内容发生变化时都会写入新的目录,这是索引存在的目的之一,这样就不会为每次更改都生成新的树,但它可以帮助您在编写脚本时保持对这一点的了解:如果示例中的“tabulous”只是一个目录而不是子模块,那么它将没有自己的索引条目(因为保持该 id 为最新是索引存在的不必要开销之一,以避免这种不必要开销)。

解决方案 2:

虽然已经过去了一年半,但我碰巧能够回答这个问题。:)

什么是gitlink入口?

基本上,它是超级项目记住子模块提交的记录。

入口在哪gitlink

来自描述:

超级项目通过 path/to/bar 树中的 gitlink 条目跟踪子模块

它是一个条目,字面意思是它是列表的一项。

因此,上面提到的这棵树是条目所在的超级项目的gitlink

在 Git 中,是目录(又称列表)的快照。

gitlink寻找入口的简单实验

➜  hustnzj git init super
Initialized empty Git repository in /hustnzj/super/.git/
➜  hustnzj cd super
➜  super git:(main) git init sub
Initialized empty Git repository in /hustnzj/super/sub/.git/
➜  super git:(main) ✗ cd sub
➜  sub git:(main) touch 1
➜  sub git:(main) ✗ git add 1
➜  sub git:(main) ✗ git commit -m 'first'
[main (root-commit) a1a76ac] first
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 1
➜  sub git:(main) ..
➜  super git:(main) ✗ git status
On branch main

No commits yet

Untracked files:
  (use "git add <file>..." to include in what will be committed)
    sub/

nothing added to commit but untracked files present (use "git add" to track)
➜  super git:(main) ✗ git submodule add ./sub sub
Adding existing repo at 'sub' to the index
➜  super git:(main) ✗ git status
On branch main

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
    new file:   .gitmodules
    new file:   sub

➜  super git:(main) ✗ git commit -m 'add submodule'
[main (root-commit) d48efa0] add submodule
 2 files changed, 4 insertions(+)
 create mode 100644 .gitmodules
 create mode 160000 sub
➜  super git:(main) git cat-file commit main
tree 32d1e97cda3fc75ad358b18a7c938fccc3be2a88
author hustnzj hustnzj@example.com 1663992891 +0800
committer hustnzj hustnzj@example.com 1663992891 +0800

add submodule
➜  super git:(main) git ls-tree 32d1e97
100644 blob c489803d5bdec1755f650854fe7ef5ab7a3ee58d    .gitmodules
160000 commit a1a76ac0bc49478d5bce1b1b598dc6c290c28003  sub

注意条目160000的模式sub。这是 Git 中的一种特殊模式,基本上意味着您将提交记录为目录条目,而不是子目录或文件。

检查a1a76ac0bc49478d5bce1b1b598dc6c290c28003提交是否是子模块的提交sub

super git:(main) git -C sub rev-parse HEAD
a1a76ac0bc49478d5bce1b1b598dc6c290c28003

如果您在将子模块作为子模块添加到超级项目中时注意上面的输出,您应该会看到该160000模式。

160000您可以在这里找到清晰的解释。

160000:gitlink,对象的 SHA-1 指向另一个存储库中的提交。Git 链接只能通过 SHA 或提交标记指定。它们用于实现子模块。

相关推荐
  政府信创国产化的10大政策解读一、信创国产化的背景与意义信创国产化,即信息技术应用创新国产化,是当前中国信息技术领域的一个重要发展方向。其核心在于通过自主研发和创新,实现信息技术应用的自主可控,减少对外部技术的依赖,并规避潜在的技术制裁和风险。随着全球信息技术竞争的加剧,以及某些国家对中国在科技领域的打压,信创国产化显...
工程项目管理   2599  
  为什么项目管理通常仍然耗时且低效?您是否还在反复更新电子表格、淹没在便利贴中并参加每周更新会议?这确实是耗费时间和精力。借助软件工具的帮助,您可以一目了然地全面了解您的项目。如今,国内外有足够多优秀的项目管理软件可以帮助您掌控每个项目。什么是项目管理软件?项目管理软件是广泛行业用于项目规划、资源分配和调度的软件。它使项...
项目管理软件   1556  
  IPD(Integrated Product Development)流程作为一种先进的产品开发管理模式,在众多企业中得到了广泛应用。其中,技术评审与决策评审是IPD流程中至关重要的环节,它们既有明显的区别,又存在紧密的协同关系。深入理解这两者的区别与协同,对于企业有效实施IPD流程,提升产品开发效率与质量具有重要意义...
IPD管理流程   38  
  本文介绍了以下10款项目管理软件工具:禅道项目管理软件、ClickUp、Freshdesk、GanttPRO、Planview、Smartsheet、Asana、Nifty、HubPlanner、Teamwork。在当今快速变化的商业环境中,项目管理软件已成为企业提升效率、优化资源分配和确保项目按时交付的关键工具。然而...
项目管理系统   32  
  建设工程项目质量关乎社会公众的生命财产安全,也影响着企业的声誉和可持续发展。高质量的建设工程不仅能为使用者提供舒适、安全的环境,还能提升城市形象,推动经济的健康发展。在实际的项目操作中,诸多因素会对工程质量产生影响,从规划设计到施工建设,再到后期的验收维护,每一个环节都至关重要。因此,探寻并运用有效的方法来提升建设工程...
工程项目管理制度   28  
热门文章
项目管理软件有哪些?
曾咪二维码

扫码咨询,免费领取项目管理大礼包!

云禅道AD
禅道项目管理软件

云端的项目管理软件

尊享禅道项目软件收费版功能

无需维护,随时随地协同办公

内置subversion和git源码管理

每天备份,随时转为私有部署

免费试用