需求:1. 一个项目有三个环境,开发的即开发者本地调试的环境,测试的用于测试人员质控的环境,生产的用于用户的环境
2. 三个环境对应各自单独的服务地址
3. 每个环境有自己单独的环境配置
(以上的需求可通过设置环境变量来完成,但是我们这次的方式更适合前端新手来分离三个不同的环境,比如Vue的脚手架搭建的项目只有开发和生产两个环境变量,测试的环境变量需要自己再配一遍,如果通过git来分离三个不同的环境分支,一是更简洁易上手,二是有利于多人员的开发)
第一步:新建一个master分支,即为生产环境,添加该环境的特殊环境配置
第二步:新建一个test分支,即为测试环境,添加该环境的特殊环境配置
第三步:新建一个feature分支,即为开发环境,添加该环境的特殊环境配置
(下面新建你的任务认知,其中git checkout -b new-feature/t999,是本地新建一个任务分支,任务号和开发平台任务号对应;git push --set-upstream origin new-feature/t999,是当前分支与远程分支关联,之后再在这个分支上修改提交的时候只用git push了)
PS H:\previousJobAndOtherConfig\pc-common-frame> git checkout -b new-feature/t999
Switched to a new branch 'new-feature/t999'
PS H:\previousJobAndOtherConfig\pc-common-frame> git add .
PS H:\previousJobAndOtherConfig\pc-common-frame> git commit -m 'feature: create new-feature/t999'
[new-feature/t999 c5c35db] feature: create new-feature/t999
1 file changed, 1 deletion(-)
PS H:\previousJobAndOtherConfig\pc-common-frame> git push
fatal: The current branch new-feature/t999 has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin new-feature/t999
PS H:\previousJobAndOtherConfig\pc-common-frame> git push --set-upstream origin new-feature/t999
Enumerating objects: 11, done.
Counting objects: 100% (11/11), done.
Delta compression using up to 4 threads
Compressing objects: 100% (4/4), done.
Writing objects: 100% (6/6), 464 bytes | 154.00 KiB/s, done.
Total 6 (delta 3), reused 0 (delta 0)
* [new branch] new-feature/t999 -> new-feature/t999
Branch 'new-feature/t999' set up to track remote branch 'new-feature/t999' from 'origin'.
以下是平常的开发情况,在当前分支开发完成之后,将本地代码提交到远程,再合并到测试环境;
测试环境质控完成之后,再合并到生产环境
(此时合并并不会影响各自环境的环境配置,注意每个环境的环境配置需要在当前环境分支更改的,不然合并的时候会被覆盖)
PS H:\previousJobAndOtherConfig\pc-common-frame> git checkout test
Switched to branch 'test'
Your branch is up to date with 'origin/test'.
PS H:\previousJobAndOtherConfig\pc-common-frame> git merge new-feature/t999
Updating 5390525..c5c35db
Fast-forward
src/views/home/personalCenter.vue | 1 -
1 file changed, 1 deletion(-)
PS H:\previousJobAndOtherConfig\pc-common-frame> git push
Total 0 (delta 0), reused 0 (delta 0)
5390525..c5c35db test -> test
备注:当你在某个分支开发的时候,上面有紧急任务,需要修改之前某个功能的bug,此时你这个分支的内容没开发完,这时候你可以这么做 ==> 贮藏(注意新建的文件需要暂存add之后再贮藏)
git stash(这时会生成一个带有编码的贮藏,你当前分支就是clean的,可以切换到你feature分支上,新建一个这个bug的任务号的分支开发完成之后切换到你之前在写的那个功能分支)
git stash apply “贮藏的编码” (比如stash@{0}) git stash pop(删除贮藏的内容并应用;如果你的贮藏只有一个,建议使用)
关于贮藏的详解,请移步https://blog.csdn.net/qq_36898043/article/details/79431168