子模块的使用
克隆项目后,默认子模块目录下无任何内容。需要在项目根目录执行如下命令完成子模块的下载:
git submodule init
git submodule update
或者
git submodule update --init --recursive
拉取子模块最新内容
git submodule foreach git pull
添加子模块
git submodule add https://子模块.git 项目子模块path
添加完毕后,项目里同时会生成 .gitmodules文件
如果添加报错
xxx目录 already exists in the index
则执行
git rm -r --cached xxx目录
更新子模块
cd module_dir/ #子模块目录
git fetch
git merge origin/master
标题问题汇总
- You are not currently on a branch.
You are not currently on a branch. Please specify which branch you want to merge with. See git-pull(1) for details.
解决办法:
首先git checkout -b temp
其次git checkout master
即可恢复到master repository的状态,然后就可以了。
切换分支失败
error: Your local changes to the following files would be overwritten by checkout:
toutiao/baike/message/notify.thrift
Please commit your changes or stash them before you switch branches.
Aborting
解决办法:
强制切换:git checkout -f master
解决方法2
git reset --hard
git pull