最短的文字说明 git submodule 的原理

in #git6 years ago (edited)

git submodule 的那几个命令每次查完都记不住, 所以这次就在这里好好思考一下其原理, 希望以后不要再忘了.

git submodule 的原理是在父模块中记录子模块的 commit, 并监控记录的 commit 和子模块的 HEAD 的差异.

父模块所记录的子模块 commit 属于父模块的版本信息, 这一信息的改变不会实际影响子模块的 HEAD. 当 cd 到子模块中做了一些更改提交, 或者父模块从远程 fetch 最新改动, 只要是会导致父模块记录的 commit 和子模块中 HEAD 不一样时, 父模块 git status 就会显示出这一差异, git submodule update 命令会将子模块的 HEAD 指向父模块中记录的 commit id, 从而抹平这一差异.

如果想让子模块的 HEAD 更新到子模块的远程最新, 就用 git submodule update —remote, 这样一来子模块的 HEAD 一般往往也就比父模块记录的 commit 要新了, 父模块 git status 自然也会显示差异, 父模块可以提交这一信息将其记录在自身 --- 这就是父模块 "携带" 某个特定版本子模块的方法.

Sort:  

为来自祖国的大咖点赞

多谢~ 不过我不是大咖, 一起学习~

一起加油👌

为来自祖国的大咖点赞

为来自祖国的大咖点赞

You should follow @icowatchdog. ICO Watchdog is your comprehensive solution to following the cryptocurrency market. Follow the market with 100% Free and Real-time cryptocurrency alerts for all your favorite messaging applications today. Follow @icowatchdog Steemit account for news updates and token sales/air drops.

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.034
BTC 64136.70
ETH 3128.20
USDT 1.00
SBD 3.94