Git submodules使用方法
1.构建submodule实例
Step1:下载git父仓库
cd /root/workspace
git clone https://github.com/daneren/main_project.git
Step2:添加git子仓库
cd /root/workspace/main_project
git submodule add https://github.com/daneren/sub_project.git
Step3:初始化mian_project
git submodule update --init --recursive
Step3:查看状态
cd /root/workspace/main_project
git status
cd /root/workspace/main_project/sub_project
git status
git branch -a
git checkout main
git branch -a
Step4:更新主仓库
cd /root/workspace/mian_project
git commit -am 'add submodule sub_project'
git push
2.下载submodule实例
直接下载克隆含有子模块的项目
git clone https://github.com/daneren/main_project.git
cd main_project/
git submodule update --init --recursive
or
git clone --recurse-submodules https://github.com/daneren/main_project.git
3.修改sub_project并在mian_project同步
修改sub_project
cd /root/workspace/mian_project/sub_project
echo "This is a submodule." > new.txt
git status
git branch -a
git add .
git commit -m 'add new.txt'
git push origin HEAD:main
mian_project同步
cd /root/workspace/mian_project/
git status
git add .
git commit -m "update submodule add new.txt"
git push
单独下载sub_project修改并提交,在原有main_project更新到最新sub_project remote commit
cd /root/workspace/
git clone git@github.com:daneren/sub_project.git
cd sub_project
echo "This is a new2 file." > new2.txt
git add . && git commit -m 'add new2.txt'
git push
# init main_project
rm -rf /root/workspace/main_project
# update main_project
cd /root/workspace/
git clone https://github.com/daneren/main_project.git
cd /root/workspace/main_project
git submodule update --init --recursive
# Submodule 'sub_project' (https://github.com/daneren/sub_project.git) registered for path 'sub_project'
# Cloning into '/data/workspace/main_project/sub_project'...
# Submodule path 'sub_project': checked out 'ceee669bd8e29bb3cf2c049af0b4b7613208f952'
# 选择sub_projrct branch 拉取最新代码
git pull origin HEAD:main
git add .
git commit -m 'update submodule add new2.txt'
git push
|