Git 项目分离

应用场景:

box项目目录结构如下:

​ –server
​ –frontend
​ –configs
​ –docs
​ –jobs
​ –fabtask
​ –migrations
​ –config.py
​ –fabfile.py
​ –handler.py
​ –manage.py
​ –README.md
​ –requirements.txt

  1. 删除frontend文件夹,创建新的项目box-server
  2. 抽出frontend文件夹,创建新的项目box-web
  3. 抽出configs/ fabtask/ docs/ fabfile.py config.py,创建新的项目box-deploy

分离box-server项目

  1. 创建新项目box-server
  2. git clone box-repository-url box-server
  3. cd box-server
  4. git filter-branch --tree-filter 'rm -rf frontend' --prune-empty -- --all
  5. git remote set-url origin box-server-repository-url
  6. git push --all origin

分离box-web项目

  1. 创建新项目box-web
  2. git clone box-repository-url box-web
  3. cd box-web
  4. git filter-branch --prune-empty --subdirectory-filter frontend/ -- --all
  5. git remote set-url origin box-web-respository-url
  6. git push --all origin

分离box-deploy项目

  1. 创建新项目box-deploy
  2. git clone box-repository-url box-deploy
  3. cd box-deploy
  4. git filter-branch --index-filter 'git rm --cached -qr --ignore-unmatch -- . && git reset -q $GIT_COMMIT -- configs/ fabtask/ docs/ fabfile.py config.py' --prune-empty -- --all
  5. git remote set-url origin box-deploy-repository-url
  6. git push