惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

B
Blog
V
Vulnerabilities – Threatpost
P
Proofpoint News Feed
Google DeepMind News
Google DeepMind News
Y
Y Combinator Blog
V
Visual Studio Blog
阮一峰的网络日志
阮一峰的网络日志
腾讯CDC
月光博客
月光博客
T
Troy Hunt's Blog
博客园_首页
H
Hackread – Cybersecurity News, Data Breaches, AI and More
N
Netflix TechBlog - Medium
Microsoft Security Blog
Microsoft Security Blog
Recorded Future
Recorded Future
Blog — PlanetScale
Blog — PlanetScale
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Scott Helme
Scott Helme
T
Threat Research - Cisco Blogs
P
Palo Alto Networks Blog
T
The Exploit Database - CXSecurity.com
Simon Willison's Weblog
Simon Willison's Weblog
Know Your Adversary
Know Your Adversary
SecWiki News
SecWiki News
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Threatpost
Forbes - Security
Forbes - Security
S
Schneier on Security
P
Proofpoint News Feed
T
Tor Project blog
Cyberwarzone
Cyberwarzone
The Hacker News
The Hacker News
Cloudbric
Cloudbric
S
Security @ Cisco Blogs
Webroot Blog
Webroot Blog
Attack and Defense Labs
Attack and Defense Labs
Hacker News: Ask HN
Hacker News: Ask HN
Google DeepMind News
Google DeepMind News
Hacker News - Newest:
Hacker News - Newest: "LLM"
C
CERT Recently Published Vulnerability Notes
The Last Watchdog
The Last Watchdog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
S
SegmentFault 最新的问题
V
V2EX
量子位
B
Blog RSS Feed
宝玉的分享
宝玉的分享
T
The Blog of Author Tim Ferriss
罗磊的独立博客
J
Java Code Geeks

流动

对口型视频合成方案对比:Wav2Lip、VideoReTalking 与 MuseTalk 2026 音色克隆方案对比:IndexTTS-2、CosyVoice、GPT-SoVITS、Fish Speech、VoxCPM 部署与实测 AI Agent折腾记(OpenClaw / Hermes Agent) 我的2025年 大连之行 回家收麦 六一儿童节爬长城 Golang database/sql 数据库断线自动重连机制解析 Golang默认Http Client导致的cannot assign requested address错误 清明踏春,爬山看海 购入小牛G400T电动车 北京的三月飞雪 wrenAI本地LLM模型部署 天津一日游 2024年终总结 停止使用staticfile.org服务 使用 ImageMagick 自动添加水印,保护图片版权 如何注册一个.sol域名 奥森公园半日游 昌平42公里骑行绿道打卡 十月一日爬慕田峪长城 当Hugo遇上AVIF,优化图片加载 博客被恶意镜像 Github Pages 部署流程解析 搭建个人锻炼页面 你好 Follow 中秋爬山 Google Adsense的审核之旅 让你的IPFS站点持久在线:接入Filebase的Names(IPNS)服务 一次简短的青岛之行 解决 "undeclared name: any (requires version go1.18 or later)" 编译错误 搭建自托管IPFS Gateway服务,替代Cloudflare的IPFS Gateway 302跳转的跨域问题(CORS) GORM增加sqlcommenter特性 源码分析:GORM是如何生成sql的 工银亚洲网银密码重置 加速Cloudflare访问 2023年终总结 2023年12月北京暴雪记录 使用Hugo实现响应式和优化的图片 加速Google Analytics 使用Google Indexing API加速博客收录 在Netlify上部署Twikoo评论系统 利用Github Actions定时抓取微博 北大口腔牙周刮治记录 故乡回忆之旅 解决Golang使用go get安装包后找不到可执行文件的问题 修正Hugo的JSON Feed格式 我的学车之路 将博客部署到星际文件系统(IPFS) 新冠疫情后的第一个春节 第一次清理键盘 2022年终总结 去掉Cloudflare烦人的email-decode.min.js请求 累计布局偏移修复方案改进 —— 自动生成图片宽高 优化博客的累计布局偏移(CLS)问题 将博客部署到Cloudflare Pages 奥林匹克公园向日葵之旅 记第二次洗牙 记录2022年海淀幼升小 Golang解析json的一个问题 疫情下的生活 整理下博客的一些调整 疫情下的五一假期 自己动手,更换thinkpad x1硬盘 二刷百望山 带娃游颐和园 博客架构说明 难得的清明假期 十一年的等待,终于拿到了liudon.com域名 被隔离的一周 mysql中字符串和整型自动转换的问题 一次惊心动魄的Mysql更新操作 如何在北京公积金网站上修改婚姻状况 PHP7.2编译安装后没有php.ini文件的问题 检测网站支持的SSL/TLS协议版本 记一次难忘的手术经历 十一假期经历 Swoft 框架运行分析(五) —— ConsoleProcessor模块分析 Swoft 框架运行分析(四) —— EventProcessor模块分析 一个Curl的耗时长的问题 Swoft 框架运行分析(三) —— BeanProcessor模块分析 Swoft 框架运行分析(二) —— AnnotationProcessor模块分析 Swoft 框架运行分析(一) BCMath 与 科学计数 Flink Could Not Resolve Resourcemanager Address 解决Sublime Text安装包时"There Are No Packages Available for Installation"的报错 关于本站 2019,新开始
一个git submodule update引发的问题
Liudon · 2019-09-06 · via 流动

背景

1月份的时候,用hugo搭了这套博客系统。

本机写md文件,更新到github,然后通过travis-ci自动发布。

jane主题是通过git submodule引入的,.gitmodules文件内容。

[submodule "themes/jane"]
	path = themes/jane
	url = https://github.com/xianmin/hugo-theme-jane.git

问题

最近几天更新完文章后,发现首页显示出了问题。

一开始以为是主题有问题,具体描述见首页文章不显示了

issue里: shaform提到使用的并不是最新的版本。 RocFang提到是git submodule使用的问题。

但是travis-ci每次都是通过git submodule update --init --recursive更新子仓库代码的,为什么会不是最新的代码呢。

问题重现

接下来,我们用一个新的仓库,来模拟重现一下。

  1. 克隆仓库。

    [root@VM_81_18_centos xx]# git clone git@github.com:Liudon/test.git
    Cloning into 'test'...
    [root@VM_81_18_centos test]# 
    
  2. 添加文件。

     [root@VM_81_18_centos xx]# cd test/
     [root@VM_81_18_centos test]# echo "# test" >> README.md
     [root@VM_81_18_centos test]# git add README.md
     [root@VM_81_18_centos test]# 
    
  3. 引用子仓库。

     [root@VM_81_18_centos test]# git submodule add git@github.com:xianmin/hugo-theme-jane.git theme/jane
     Cloning into 'theme/jane'...
     remote: Enumerating objects: 216, done.
     remote: Counting objects: 100% (216/216), done.
     remote: Compressing objects: 100% (128/128), done.
     remote: Total 6165 (delta 102), reused 159 (delta 65), pack-reused 5949
     Receiving objects: 100% (6165/6165), 3.05 MiB | 1.70 MiB/s, done.
     Resolving deltas: 100% (3443/3443), done.
    
  4. 查看文件列表。

     [root@VM_81_18_centos test]# ll
     total 8
     -rw-r--r-- 1 root root    5 Sep  6 16:05 README.md
     drwxr-xr-x 7 root root 4096 Sep  6 16:08 typecho
     [root@VM_81_18_centos test]# 
    
  5. 查看状态。

    [root@VM_81_18_centos test]# git status
    # On branch master
    #
    # Initial commit
    #
    # Changes to be committed:
    #   (use "git rm --cached <file>..." to unstage)
    #
    #	new file:   .gitmodules
    #	new file:   README.md
    #	new file:   typecho
    #
    [root@VM_81_18_centos test]# 
    
  6. 查看修改。

    [root@VM_81_18_centos test]# git diff --cached
    diff --git a/.gitmodules b/.gitmodules
    new file mode 100644
    index 0000000..b1ddf70
    --- /dev/null
    +++ b/.gitmodules
    @@ -0,0 +1,3 @@
    +[submodule "typecho"]
    +       path = typecho
    +       url = https://github.com/Liudon/typecho
    diff --git a/README.md b/README.md
    new file mode 100644
    index 0000000..9daeafb
    --- /dev/null
    +++ b/README.md
    @@ -0,0 +1 @@
    +test
    diff --git a/typecho b/typecho
    new file mode 160000
    index 0000000..b0c4cc7
    --- /dev/null
    +++ b/typecho
    @@ -0,0 +1 @@
    +Subproject commit b0c4cc77a7f8f04661fb9f75d4ba6d4d7915b0f1
    [root@VM_81_18_centos test]# 
    

    注意最后一行Subproject commit b0c4cc77a7f8f04661fb9f75d4ba6d4d7915b0f1

    这个commitId是子仓库最新提交的记录id,对应的修改记录

  7. 提交修改。

    [root@VM_81_18_centos test]# git push -u origin master
    Counting objects: 4, done.
    Compressing objects: 100% (3/3), done.
    Writing objects: 100% (4/4), 362 bytes | 0 bytes/s, done.
    Total 4 (delta 0), reused 0 (delta 0)
    To git@github.com:Liudon/test.git
    * [new branch]      master -> master
    Branch master set up to track remote branch master from origin.
    [root@VM_81_18_centos test]# 
    

    提交后,在github上子仓库后面会多显示一个@xxxxx,这里就是引用的commitId,对应到前面git diff最后一行。

    点击查看提交记录

    本次提交的commitId5b11d515db8ad8d299ef1691f115590e0015c3b7,子仓库typecho单独记录了引入时的commitId,为b0c4cc77a7f8f04661fb9f75d4ba6d4d7915b0f1,对应的提交记录

  8. 接下来克隆子仓库,进行更新提交。

    [root@VM_81_18_centos xx]# git clone git@github.com:Liudon/typecho.git
    Cloning into 'typecho'...
    remote: Enumerating objects: 1, done.
    remote: Counting objects: 100% (1/1), done.
    remote: Total 7179 (delta 0), reused 0 (delta 0), pack-reused 7178
    Receiving objects: 100% (7179/7179), 7.26 MiB | 2.02 MiB/s, done.
    Resolving deltas: 100% (4844/4844), done.
    [root@VM_81_18_centos xx]# 
    [root@VM_81_18_centos xx]# cd typecho/
    [root@VM_81_18_centos typecho]# git log -n 1
    commit b0c4cc77a7f8f04661fb9f75d4ba6d4d7915b0f1
    Merge: c904005 8fd7492
    Author: 祁宁 <magike.net@gmail.com>
    Date:   Tue Nov 18 13:59:52 2014 +0800
    
        Merge branch 'master' of https://github.com/typecho/typecho
    [root@VM_81_18_centos typecho]#
    

    通过git log,确认最新的提交commitId为b0c4cc77a7f8f04661fb9f75d4ba6d4d7915b0f1,与前面的引入的一致。

    [root@VM_81_18_centos typecho]# echo "xxx" > test
    [root@VM_81_18_centos typecho]# 
    [root@VM_81_18_centos typecho]# git add test
    [root@VM_81_18_centos typecho]# git commit -m 'test'
    [master 5dcc8f4] test
    1 file changed, 1 insertion(+)
    create mode 100644 test
    [root@VM_81_18_centos typecho]# git push
    Counting objects: 4, done.
    Compressing objects: 100% (2/2), done.
    Writing objects: 100% (3/3), 252 bytes | 0 bytes/s, done.
    Total 3 (delta 1), reused 0 (delta 0)
    remote: Resolving deltas: 100% (1/1), completed with 1 local object.
    To git@github.com:Liudon/typecho.git
    b0c4cc7..5dcc8f4  master -> master
    [root@VM_81_18_centos typecho]# 
    

    修改文件提交。

    [root@VM_81_18_centos typecho]# git log -n 1
    commit 5dcc8f4e91cc724ba82aba5b9e7955727b58c5c2
    Author: liudon <i.mu@qq.com>
    Date:   Fri Sep 6 16:26:47 2019 +0800
    
        test
    [root@VM_81_18_centos typecho]#
    

    最新提交的commitId5dcc8f4e91cc724ba82aba5b9e7955727b58c5c2

  9. 重新克隆test库。

    [root@VM_81_18_centos yy]# git clone git@github.com:Liudon/test.git
    Cloning into 'test'...
    remote: Enumerating objects: 4, done.
    remote: Counting objects: 100% (4/4), done.
    remote: Compressing objects: 100% (3/3), done.
    remote: Total 4 (delta 0), reused 4 (delta 0), pack-reused 0
    Receiving objects: 100% (4/4), done.
    [root@VM_81_18_centos yy]# cd test/
    [root@VM_81_18_centos test]# ll
    total 8
    -rw-r--r-- 1 root root    5 Sep  6 16:31 README.md
    drwxr-xr-x 2 root root 4096 Sep  6 16:31 typecho
    [root@VM_81_18_centos test]# ll typecho/
    total 0
    [root@VM_81_18_centos test]# 
    

    这里可以看到typecho目录下是没有文件的。

    [root@VM_81_18_centos test]# git submodule update --init --recursive
    Submodule 'typecho' (https://github.com/Liudon/typecho) registered for path 'typecho'
    Cloning into 'typecho'...
    remote: Enumerating objects: 4, done.
    remote: Counting objects: 100% (4/4), done.
    remote: Compressing objects: 100% (3/3), done.
    remote: Total 7182 (delta 0), reused 2 (delta 0), pack-reused 7178
    Receiving objects: 100% (7182/7182), 7.26 MiB | 1.26 MiB/s, done.
    Resolving deltas: 100% (4844/4844), done.
    Submodule path 'typecho': checked out 'b0c4cc77a7f8f04661fb9f75d4ba6d4d7915b0f1'
    [root@VM_81_18_centos test]#
    

    更新子仓库代码,这里可以看到最终checkout的版本为b0c4cc77a7f8f04661fb9f75d4ba6d4d7915b0f1,与前面提交时的版本一致。

问题分析

git submodule add的时候,会记录当时引入时子仓库的版本id。

git submodule update --init --recursive,会检出引入时的仓库版本,这就是为啥代码没有更新了。

问题解决

[root@VM_81_18_centos yy]# git clone git@github.com:Liudon/test.git
Cloning into 'test'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 4 (delta 0), pack-reused 0
Receiving objects: 100% (4/4), done.
[root@VM_81_18_centos yy]# 
[root@VM_81_18_centos yy]# 
[root@VM_81_18_centos yy]# cd test/
[root@VM_81_18_centos test]# ll
total 8
-rw-r--r-- 1 root root    5 Sep  6 16:37 README.md
drwxr-xr-x 2 root root 4096 Sep  6 16:37 typecho
[root@VM_81_18_centos test]# ll typecho/
total 0
[root@VM_81_18_centos test]# 
[root@VM_81_18_centos test]# git submodule update --init --remote --recursive
Submodule 'typecho' (https://github.com/Liudon/typecho) registered for path 'typecho'
Cloning into 'typecho'...
remote: Enumerating objects: 4, done.
remote: Counting objects: 100% (4/4), done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 7182 (delta 0), reused 2 (delta 0), pack-reused 7178
Receiving objects: 100% (7182/7182), 7.26 MiB | 1.24 MiB/s, done.
Resolving deltas: 100% (4844/4844), done.
Submodule path 'typecho': checked out '5dcc8f4e91cc724ba82aba5b9e7955727b58c5c2'
[root@VM_81_18_centos test]#

使用git submodule update --init --remote --recursive命令。