假设您的主分支包含整个项目:
|--BackOffice
| \--UI
|--BackOffice.UI
| \--WebControls
|--BackOfficeTests
|--Deployment
| \--db
|--BusinessLogicLayer
| |--bin
| |--obj
| \--Properties
|--scripts
|--Website
| |--admin
| |--App_Browsers
| |--App_Code
| |--App_Data
| |--Styles
| |--web.config
现在,所有网站共同的任何更改都会被提交到这个分支。
为不同的网站创建单独的分支。例如:
从主分支开始,
git checkout -b site1
git checkout -b site2
git checkout -b site3
git checkout -b site4
现在,每当您想要更改任何特定网站文件,例如Styles文件夹或web.config,请在这些分支中进行更改。
现在是部署部分。假设您想要部署site1,请在本地系统上基于主分支创建一个临时分支,将site1分支合并到其中并部署它。最后删除临时分支。
git checkout -b temp
git merge site1
打包您的代码成 tar 或 zip 格式并部署。之后,
git checkout master
git branch -D temp
如果您不想公开部署方式,甚至可以编写一个小的Shell脚本来完成此操作。我们将其称为 deploy.sh 例如:
#!/bin/bash
if [ ! $1 ]; then
echo "Please pass in the name of the site you want to deploy."
exit 1
fi
#Check if we are on master branch
git status | grep "On branch master"
if [ $? -ne 0 ]; then
echo "You are not on master. Please execute 'git checkout master'"
exit 1
fi
#Check if the entered site for deployment actually exists
git branch | grep $1 || { echo "No branch $1 exists for deployment."; exit 1; }
#Update from remote
git checkout -b temp
git merge $1
tar -cvf deploy-$1.tar ./deploy.sh *
[ $? -ne 0 ] && echo "Some problem archiving the files..." && exit 1
git checkout master
git branch -D temp
echo "Please use deploy-$1.tar file to deploy the site. Thanks."
exit 0
现在当你运行./deploy.sh site2时,这个脚本将在幕后完成所有繁琐的工作,并给你一个tar文件,你可以将其部署到生产服务器上。
希望这有所帮助...