git 子模塊的使用

thinkphp 使用 git 方式安裝下載的時候需要下載兩個項目,
分別是 應用目錄和核心框架。

開發完自己的需求的時候,
需要將代碼上傳到自己的git上面,
比如上傳到 gitee 平臺。

首先需要將應用目錄下的 .git 目錄刪掉,
然後在 gitee 平臺創建一個私有項目,
然後 remote add origin 私有項目的地址,
然後執行 git add .
會報錯項目內有子模塊。

$ git add .
warning: adding embedded git repository: thinkphp
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint:   git submodule add <url> thinkphp
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint:   git rm --cached thinkphp
hint:
hint: See "git help submodule" for more information.

這個時候執行命令

git submodule add [email protected]:liu21st/framework.git thinkphp

會提示 'thinkphp' already exists in the index
這個時候需要執行命令 git rm -f --cached thinkphp
因爲執行 git rm --cached thinkphp 會報錯如下:

error: the following file has staged content different from both the
file and the HEAD:
    thinkphp
(use -f to force removal)

執行 git pull origin master --allow-unrelated-histories 獲取平臺最新代碼
如果只執行 git pull origin master 在執行 push 的時候會報錯
具體可見博客:https://www.ujwd.cn/archives/354

解決完衝突,

git push origin master

【其他解決方案】
安裝 thinkphp 框架的時候可以選擇 composer 的方式安裝

【遇到的其他命令】
1、git merge --abort
簡單的可以理解,這個命令是迴歸到衝突之前,重新執行git pull 就能重現衝突。
具體場景看博客:https://blog.csdn.net/weixin_43883776/article/details/85062087

【參考文章】
1、https://git-scm.com/book/zh/v2/Git-%E5%B7%A5%E5%85%B7-%E5%AD%90%E6%A8%A1%E5%9D%97

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章