添加子模块:
-
git submodule add
git submodule add https://gitee.com/nanshoui/son.git
添加子模块:女儿
git submodule add https://gitee.com/nanshoui/daughter.git
添加儿子和女儿模块后的状态:
其中.gitmodule记录了模块来源信息:
第一次操作不需要add,只需要git commit -m “…”
上传到远程仓库:(父亲发朋友圈)
git push origin master
拉取整个项目
删除掉father文件,重新从远程仓库clone。
此时,克隆的文件如图:
但子模块均为空目录。
使用如下指令,会根据.gitmodule文件地址把子模块更新下来。(子模块更新–初始化–递归)
git submodule update --init --recursive
- 此时拉取的子模块都是detach的一个临时分支,对其做的改动不会被记录
子模块有新分支更新
删除father整个文件夹。
分别将son和daughter新建adult分支,重新命名:son -> adult_son,daughter ->adult_daughter。切换为主分支。
重新克隆father,并git submodule update –init –recursive恢复子模块。
进入son文件,切换adult
切回到父目录:
然后父仓库add,commit。(认可儿子长大了)
同样操作更新到daughter的adult分支。
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ cd daughter/
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/daughter ((f6964d0...))
$ git checkout master
Switched to branch 'master'
Your branch is up to date with 'origin/master'.
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/daughter (master)
$ git checkout adult
Switched to a new branch 'adult'
Branch 'adult' set up to track remote branch 'adult' from 'origin'.
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/daughter (adult)
$ cd ..
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ 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 restore <file>..." to discard changes in working directory)
modified: daughter (new commits)
no changes added to commit (use "git add" and/or "git commit -a")
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ git add daughter/
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ git commit -m "my daughter is an adult now."
[master fab8434] my daughter is an adult now.
1 file changed, 1 insertion(+), 1 deletion(-)
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ git push origin master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 6 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 254 bytes | 254.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-5.0]
To gitee.com:nanshoui/father.git
a6a793a..fab8434 master -> master
git 状态clean
删除father文件夹。
重新克隆father,并git submodule update –init –recursive恢复子模块。
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块
$ git clone git@gitee.com:nanshoui/father.git
Cloning into 'father'...
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 14 (delta 3), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (14/14), 15.73 KiB | 7.87 MiB/s, done.
Resolving deltas: 100% (3/3), done.
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块
$ cd father/
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ git submodule update --init --recursive
Submodule 'daughter' (git@gitee.com:nanshoui/daughter.git) registered for path 'daughter'
Submodule 'son' (git@gitee.com:nanshoui/son.git) registered for path 'son'
Cloning into 'E:/git子模块/father/daughter'...
Cloning into 'E:/git子模块/father/son'...
Submodule path 'daughter': checked out 'c2fc651bc7b353cfc6ab8432d9f250fd8d95673b'
Submodule path 'son': checked out 'e9e0ae3882915e6d37e8c0f1037895c7ea93e4a5'
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$
这样就完成了子模块切换分支,父目录记录更新的效果。
子模块再加子模块
-
进入到子模块内,执行上述对应添加子模块操作
-
cd
-
git add && git commit -m “…”
son 内部再添加子模块granddaughter
切换到对应目录、对应adult分支,submodule add
,然后commit,再push到origin adult分支。 BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master) $ cd son BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/son ((e9e0ae3...)) $ git checkout adult Switched to a new branch 'adult' Branch 'adult' set up to track remote branch 'adult' from 'origin'. BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/son (adult) $ git submodule add git@gitee.com:nanshoui/granddaughter.git Cloning into 'E:/git子模块/father/son/granddaughter'... remote: Enumerating objects: 7, done. remote: Counting objects: 100% (7/7), done. remote: Compressing objects: 100% (6/6), done. remote: Total 7 (delta 1), reused 0 (delta 0), pack-reused 0 Receiving objects: 100% (7/7), 14.91 KiB | 1.66 MiB/s, done. Resolving deltas: 100% (1/1), done. warning: LF will be replaced by CRLF in .gitmodules. The file will have its original line endings in your working directory BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/son (adult) $ ls LICENSE adult_son.c granddaughter/ BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/son (adult) $ git status On branch adult Your branch is up to date with 'origin/adult'. Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: .gitmodules new file: granddaughter BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/son (adult) $ git commit -m "I had a daughter." [adult c018f70] I had a daughter. 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 granddaughter BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/son (adult) $ git push origin adult Enumerating objects: 4, done. Counting objects: 100% (4/4), done. Delta compression using up to 6 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 452 bytes | 452.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 remote: Powered by GITEE.COM [GNK-5.0] To gitee.com:nanshoui/son.git e9e0ae3..c018f70 adult -> adult BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/son (adult) $
切换到对应目录、对应分支,然后add && commit,再push到origin 对应分支。
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/son (adult) $ cd .. BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master) $ 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 restore <file>..." to discard changes in working directory) modified: son (new commits) no changes added to commit (use "git add" and/or "git commit -a") BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master) $ git add son/ BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master) $ git commit -m "I had a granddaughter." [master ab41179] I had a granddaughter. 1 file changed, 1 insertion(+), 1 deletion(-) BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master) $ git push origin master Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Delta compression using up to 6 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 246 bytes | 246.00 KiB/s, done. Total 2 (delta 1), reused 0 (delta 0), pack-reused 0 remote: Powered by GITEE.COM [GNK-5.0] To gitee.com:nanshoui/father.git fab8434..ab41179 master -> master BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master) $
删除father文件夹,重新克隆更新一下。
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块 $ rm -rf father/ BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块 $ git clone git@gitee.com:nanshoui/father.git Cloning into 'father'... remote: Enumerating objects: 16, done. remote: Counting objects: 100% (16/16), done. remote: Compressing objects: 100% (15/15), done. remote: Total 16 (delta 4), reused 0 (delta 0), pack-reused 0 Receiving objects: 100% (16/16), 15.94 KiB | 1.77 MiB/s, done. Resolving deltas: 100% (4/4), done. BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块 $ cd father/ BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master) $ git submodule update --init --recursive Submodule 'daughter' (git@gitee.com:nanshoui/daughter.git) registered for path 'daughter' Submodule 'son' (git@gitee.com:nanshoui/son.git) registered for path 'son' Cloning into 'E:/git子模块/father/daughter'... Cloning into 'E:/git子模块/father/son'... Submodule path 'daughter': checked out 'c2fc651bc7b353cfc6ab8432d9f250fd8d95673b' Submodule path 'son': checked out 'c018f70a472a79f7a73c7002db6657e6298780c3' Submodule 'granddaughter' (git@gitee.com:nanshoui/granddaughter.git) registered for path 'son/granddaughter' Cloning into 'E:/git子模块/father/son/granddaughter'... Submodule path 'son/granddaughter': checked out '7574fcbb939dbb045e62850c6c235ef643fa2adc' BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master) $
至此完成了子模块再加子模块。
类似的给daughter添加一个grandson子模块。
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master) $ cd daughter/ BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/daughter ((c2fc651...)) $ git checkout adult Switched to a new branch 'adult' Branch 'adult' set up to track remote branch 'adult' from 'origin'. BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/daughter (adult) $ git submodule add git@gitee.com:nanshoui/grandson.git Cloning into 'E:/git子模块/father/daughter/grandson'... remote: Enumerating objects: 7, done. remote: Counting objects: 100% (7/7), done. remote: Compressing objects: 100% (6/6), done. remote: Total 7 (delta 1), reused 0 (delta 0), pack-reused 0 Receiving objects: 100% (7/7), 14.90 KiB | 1.86 MiB/s, done. Resolving deltas: 100% (1/1), done. warning: LF will be replaced by CRLF in .gitmodules. The file will have its original line endings in your working directory BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/daughter (adult) $ git status On branch adult Your branch is up to date with 'origin/adult'. Changes to be committed: (use "git restore --staged <file>..." to unstage) new file: .gitmodules new file: grandson BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/daughter (adult) $ git commit -m "I'm mom,now.I had a son." [adult 605447f] I'm mom,now.I had a son. 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 grandson BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/daughter (adult) $ git push origin adult Enumerating objects: 4, done. Counting objects: 100% (4/4), done. Delta compression using up to 6 threads Compressing objects: 100% (3/3), done. Writing objects: 100% (3/3), 455 bytes | 455.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 remote: Powered by GITEE.COM [GNK-5.0] To gitee.com:nanshoui/daughter.git c2fc651..605447f adult -> adult BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/daughter (adult) $ cd .. BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master) $ 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 restore <file>..." to discard changes in working directory) modified: daughter (new commits) no changes added to commit (use "git add" and/or "git commit -a") BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master) $ git add daughter BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master) $ git commit -m "I had a grandson." [master 40b50be] I had a grandson. 1 file changed, 1 insertion(+), 1 deletion(-) BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master) $ git push origin master Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Delta compression using up to 6 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 245 bytes | 245.00 KiB/s, done. Total 2 (delta 1), reused 0 (delta 0), pack-reused 0 remote: Powered by GITEE.COM [GNK-5.0] To gitee.com:nanshoui/father.git ab41179..40b50be master -> master BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master) $
删除子模块
-
git submodule deinit
-
git rm
-
假如已经update过了。要删除.git里面的modules对应的内容
-
cd
-
git add &&git commit -m “…”
情形1:子模块及对应目录都在
git没有集成一键删除子模块,只能一步一步删除。
步骤1:(口头说明)
git submodule deinit son
步骤2:删除文件夹
git rm son
步骤3:删除储藏室
cd .git/modules/
rm son/ -rf
步骤4:记录commit,上传push
操作代码:
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ git submodule deinit son
Cleared directory 'son'
Submodule 'son' (git@gitee.com:nanshoui/son.git) unregistered for path 'son'
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ ls son/
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ git rm son
rm 'son'
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ cd .git/modules/
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/.git/modules (GIT_DIR!)
$ ls
daughter/ son/
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/.git/modules (GIT_DIR!)
$ rm son -rf
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/.git/modules (GIT_DIR!)
$ ls
daughter/
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/.git/modules (GIT_DIR!)
$ cd ../..
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: .gitmodules
deleted: son
此时 :.gitmodules(户口本)被修改, son(房间)被删除。然后进行记录,上传
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ git commit -m "I kicked out my son."
[master 2ed9cbb] I kicked out my son.
2 files changed, 4 deletions(-)
delete mode 160000 son
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ git push origin master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 6 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 327 bytes | 327.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-5.0]
To gitee.com:nanshoui/father.git
40b50be..2ed9cbb master -> master
情形2:子模块在,对应目录文件为空
情形搭建:
删除对应father目录
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块
$ git clone git@gitee.com:nanshoui/father.git
Cloning into 'father'...
remote: Enumerating objects: 21, done.
remote: Counting objects: 100% (21/21), done.
remote: Compressing objects: 100% (20/20), done.
remote: Total 21 (delta 6), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (21/21), 16.40 KiB | 599.00 KiB/s, done.
Resolving deltas: 100% (6/6), done.
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块
$ cd father/
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ git submodule update --init --recursive
Submodule 'daughter' (git@gitee.com:nanshoui/daughter.git) registered for path 'daughter'
Cloning into 'E:/git子模块/father/daughter'...
Submodule path 'daughter': checked out '605447fdf6c4a4c748042744d17fa95636f3360d'
Submodule 'grandson' (git@gitee.com:nanshoui/grandson.git) registered for path 'daughter/grandson'
Cloning into 'E:/git子模块/father/daughter/grandson'...
Submodule path 'daughter/grandson': checked out '049ccab0c2c83688c3ea32d91bdd90e0a2d8c0b4'
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ git submodule add git@gitee.com:nanshoui/son.git
Cloning into 'E:/git子模块/father/son'...
remote: Enumerating objects: 12, done.
remote: Counting objects: 100% (12/12), done.
remote: Compressing objects: 100% (11/11), done.
remote: Total 12 (delta 3), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (12/12), 15.41 KiB | 526.00 KiB/s, done.
Resolving deltas: 100% (3/3), done.
warning: LF will be replaced by CRLF in .gitmodules.
The file will have its original line endings in your working directory
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ git status
On branch master
Your branch is up to date with 'origin/master'.
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
modified: .gitmodules
new file: son
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ git commit -m "I called my son back,one day"
[master c1f8e70] I called my son back,one day
2 files changed, 4 insertions(+)
create mode 160000 son
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ git push origin master
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 6 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 379 bytes | 379.00 KiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-5.0]
To gitee.com:nanshoui/father.git
2ed9cbb..c1f8e70 master -> master
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$
然后再次删除father目录
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ cd ..
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块
$ rm -rf father/
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块
$ git clone git@gitee.com:nanshoui/father.git
Cloning into 'father'...
remote: Enumerating objects: 24, done.
remote: Counting objects: 100% (24/24), done.
remote: Compressing objects: 100% (23/23), done.
remote: Total 24 (delta 9), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (24/24), 16.59 KiB | 8.29 MiB/s, done.
Resolving deltas: 100% (9/9), done.
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块
$ cd father/
此时有daughter文件夹,里面目录为空。还未执行submodule update 操作,为情形二的删除。
只需执行:
git deinit
更换子模块
- 先删除再添加
子模块更换分支
- git checkout
- 假如有更改最好先push到远程仓库
- cd
- git add &&git commit -m “…”
子模块更改后提交了且被父目录记录了更新,但未被推送至远程仓库
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块
$ rm -rf father/
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块
$ git clone git@gitee.com:nanshoui/father.git
Cloning into 'father'...
remote: Enumerating objects: 24, done.
remote: Counting objects: 100% (24/24), done.
remote: Compressing objects: 100% (23/23), done.
remote: Total 24 (delta 9), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (24/24), 16.59 KiB | 1.38 MiB/s, done.
Resolving deltas: 100% (9/9), done.
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块
$ cd father/
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ git submodule update --init --recursive
Submodule 'daughter' (git@gitee.com:nanshoui/daughter.git) registered for path 'daughter'
Submodule 'son' (git@gitee.com:nanshoui/son.git) registered for path 'son'
Cloning into 'E:/git子模块/father/daughter'...
Cloning into 'E:/git子模块/father/son'...
Submodule path 'daughter': checked out '605447fdf6c4a4c748042744d17fa95636f3360d'
Submodule 'grandson' (git@gitee.com:nanshoui/grandson.git) registered for path 'daughter/grandson'
Cloning into 'E:/git子模块/father/daughter/grandson'...
Submodule path 'daughter/grandson': checked out '049ccab0c2c83688c3ea32d91bdd90e0a2d8c0b4'
Submodule path 'son': checked out 'f041f8331d3b6699f0b0fa217549ced818562f54'
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ cd daughter/
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/daughter ((605447f...))
$ git checkout adult
Switched to a new branch 'adult'
Branch 'adult' set up to track remote branch 'adult' from 'origin'.
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/daughter (adult)
$ vi dyed_hair.c
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/daughter (adult)
$ git status
On branch adult
Your branch is up to date with 'origin/adult'.
Untracked files:
(use "git add <file>..." to include in what will be committed)
dyed_hair.c
nothing added to commit but untracked files present (use "git add" to track)
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/daughter (adult)
$ git add dyed_hair.c
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/daughter (adult)
$ git commit -m "I'm gonna dye my hair. "
[adult f20d2cd] I'm gonna dye my hair.
1 file changed, 0 insertions(+), 0 deletions(-)
create mode 100644 dyed_hair.c
这里忘记上传到远程仓库
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father/daughter (adult)
$ cd ..
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ 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 restore <file>..." to discard changes in working directory)
modified: daughter (new commits)
no changes added to commit (use "git add" and/or "git commit -a")
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ git add daughter/
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ git commit -m "daughter dyed hair."
[master c703d7f] daughter dyed hair.
1 file changed, 1 insertion(+), 1 deletion(-)
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ git push origin master
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Delta compression using up to 6 threads
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 248 bytes | 248.00 KiB/s, done.
Total 2 (delta 1), reused 0 (delta 0), pack-reused 0
remote: Powered by GITEE.COM [GNK-5.0]
To gitee.com:nanshoui/father.git
c1f8e70..c703d7f master -> master
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$
父仓库却记录了更改,并上传远程仓库。
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块
$ rm -rf father/
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块
$ git clone git@gitee.com:nanshoui/father.git
Cloning into 'father'...
remote: Enumerating objects: 26, done.
remote: Counting objects: 100% (26/26), done.
remote: Compressing objects: 100% (25/25), done.
remote: Total 26 (delta 10), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (26/26), 16.78 KiB | 8.39 MiB/s, done.
Resolving deltas: 100% (10/10), done.
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块
$ cd father/
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$ git submodule update --init --recursive
Submodule 'daughter' (git@gitee.com:nanshoui/daughter.git) registered for path 'daughter'
Submodule 'son' (git@gitee.com:nanshoui/son.git) registered for path 'son'
Cloning into 'E:/git子模块/father/daughter'...
Cloning into 'E:/git子模块/father/son'...
fatal: remote error: upload-pack: not our ref f20d2cd16f0dca1f23fae1eef09a235a7bba2efc
Fetched in submodule path 'daughter', but it did not contain f20d2cd16f0dca1f23fae1eef09a235a7bba2efc. Direct fetching of that commit failed.
BAT@DESKTOP-CV02V8K MINGW64 /e/git子模块/father (master)
$
此时出现致命:(英文的意思)
远程错误:上载包:不是我们的ref f20d2cd16f0dca1f23fae1eef09a235a7bba2efc
在子模块路径“子”中获取,但它不包含f20d2cd16f0dca1f23fae1eef09a235a7bba2efc。直接获取该提交失败。
-
克隆仓库,执行git submodule update - -init - -recursive,发现会有错误。
-
原因是父仓库记录了子模块的新版本,但子模块却未提交到远程仓库,父仓库找不到需要的子模块。
解决方法:
进入daughter回退之前的版本。然后再由father,add&commit&push,则可以解决。
未删除原来修改过的仓库
- cd
- git push origin
假如删除了原来的仓库
- cd
- git reset
- cd
- git add &&git commit -m “…”