娜尼的妮妮

导航

repo+git submodule 实现代码嵌套并且批量管理

最近有个新项目,仓库是一个个独立的,最开始的时候采用单个仓库git clone 下来,觉得效率太低 ,研究了下repo 和git submodule ,组合起来实现了代码嵌套和批量管理。

首先写一个manifest xml 文件,

<?xml version="1.0" encoding="UTF-8"?>
<manifest>
  <notice>Code Fetch='0'</notice>
  <remote fetch="${gitserver}" name="origin" review="${review_server}"/>
  <project name="${gitpath1}" path="${lcoalpath1}" revision="master"/>
  <project name="${gitpath2}" path="${lcoalpath1}/${lcoalpath2}" revision="master"/>
  <project name="${gitpath3}" path="${lcoalpath1}/${lcoalpath3}" revision="master"/>
</manifest>

然后把这个manifest 推送到manifest 仓库里。 

 

用repo init 命令拉下来这个代码,repo init -m ${manifest_name} -u ${manifest_url} , repo sync  这样会拉一套代码下来,代码结构已经实现了嵌套。但是此时在${localpath1}下git status,会发现提示需要git add 子库,子库现在对于gitpath1 这个仓库而言是一个新的文件夹。

在后面git clean 强制clean的时候这个文件夹可能会被清除,也为了保证代码看上去清爽,这时候就需要git submodule 上场了。

在${lcoalpath1} 下分别git submodule add <url> <path> 把两个子库加到git submodule 中去,然后git status, 会发现多了个.gitmodules 文件,git add , git commit git push 正常的操作流程之后,重新建个文件夹,repo init ,repo sync 下来会发现代码结构ok, git status 也不再提示是新文件要git add了。 

发现一个问题,只要不单独用git submodule 更新代码, .gitmodules 文件中的url 和branch 都是不生效的,会被repo  manifest中的path和branch 覆盖,不用担心里面的配置会对代码分支路径的影响 。这样就完美的实现了repo 控制代码,git submodule 实现代码嵌套。 

 

posted on 2021-11-05 18:15  娜尼的妮妮  阅读(1213)  评论(0编辑  收藏  举报