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

Shu*_*eng 5 linux git

在哪里可以看到 中提到的 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
Run Code Online (Sandbox Code Playgroud)

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.
Run Code Online (Sandbox Code Playgroud)

jth*_*ill 4

Git 记录添加的子模块内容的提交 ID 的方式与记录添加的文件内容的 Blob ID 的方式相同,作为 ID 列在索引或记录树中。这是一个 gitlink:您的内容位于另一个提交中,如果需要,您可以在该路径中查看。辅助git 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
Run Code Online (Sandbox Code Playgroud)

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

git -C tabulous diff-index --quiet --cached @ || echo staged changes in tabulous
git -C tabulous diff-files -q                 || echo unstaged changes in tabulous
Run Code Online (Sandbox Code Playgroud)

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

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

stdbuf -oL git -C tabulous git ls-files --exclude-standard -oi | grep -q . \
&& echo untracked, ignored files in tabulous
Run Code Online (Sandbox Code Playgroud)

(该stdbuf -oL部分仅在真正大的工作树中才重要,在该树中值得敲击键盘以避免遍历足够多的内容来找到充满名称的整个缓冲区)

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