[教學] git應用-突然出現的 submodule - 討論區

[教學] git應用-突然出現的 submodule

文章瀏覽次數 2154 文章回覆數 0

特種兵

特種兵圖像(預設)

2020-09-14 11:52:24

From:211.23.21.202

昨天趁著假日,在更新公司內部系統使用到的套件,主要是寄信系統與 excel 相關模組。

更新的技術細節不是我們要說的重點,這裡發生了 git 相關問題才是我們要分享的部分。

都更新好後在正式環境下 git status 看一下是我的習慣

$ git status

On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
  (commit or discard the untracked or modified content in submodules)

	modified:   web_data/PhpSpreadsheet/maennchen/zipstream-php (modified content)
	modified:   web_data/PhpSpreadsheet/phpoffice/phpspreadsheet (modified content)
	modified:   web_data/PhpSpreadsheet/psr/http-client (modified content)
	modified:   web_data/PhpSpreadsheet/psr/http-factory (modified content)
	modified:   web_data/PhpSpreadsheet/psr/simple-cache (modified content)
	modified:   web_data/PhpSpreadsheet/symfony/polyfill-mbstring (modified content)

no changes added to commit (use "git add" and/or "git commit -a")

奇怪了,在 local 端怎沒這個狀況?

看到上面一行關鍵字了沒:

(commit or discard the untracked or modified content in submodules)

怎麼會有這個東西跑出來?找其中一個資料夾看看:

$ cd web_data/PhpSpreadsheet/symfony/polyfill-mbstring
$ ls -a
.   bootstrap.php  .git     Mbstring.php  Resources                             
..  composer.json  LICENSE  README.md                                           
# 有看到 .git 資料夾吧,原來是套件自帶的  
# 然後在這個資料夾下 git log 看一下
$ git log -1
commit a6977d63bf9a0ad4c65cd352709e230876f9904a (HEAD, tag: v1.18.1, tag: v1.18.
 0, origin/master, origin/HEAD, master)                                          
 Author: Nicolas Grekas <nicolas.grekas@gmail.com>                               
 Date:   Tue Jul 14 14:35:20 2020 +0200                                          

     Update CHANGELOG and branch-alias                                           

# 對呀,這個提交的人不是我,而是軟體的開發或維護者

首先,我想到了一件事,就是我在用 composer 下載這個套件時有加 prefer-source

可能是這樣,會把包括原始的一些程式通通下載回來。

其實我當時主要是要看說明文件跟範例,這邊會建議大家,

如果是正式系統要用的,最好裝個比較乾淨的版本。

原本想說重新下載然後蓋掉再 commit 就好了,但原本存在的 .git 還是在。

趁這個機會來了解一下 git submodule 是什麼東西也不錯啦。

不過我目前用不到,只想把他們移掉,反正我還沒有 init 或 update submodule 就是了。

於是,我用了最笨也是最簡單的辦法,就是把上面列出來的資料夾裡的 .git 資料夾刪掉,

好吧,問題解決了。