企业团队使用Git协同开发的一般流程

  1. 云栖社区>
  2. 博客>
  3. 正文

企业团队使用Git协同开发的一般流程

迅雷老曾 2014-09-28 09:09:00 浏览2078
展开阅读全文

流程大纲

一、代码编写

1.从主分支(master)上创建开发分支(dev)。 

git branch dev

2.切换到dev。 

git checkout dev

3.在dev上进行代码编写,并提交本地版本库。 
注:一定不能直接在marster分支上修改代码

git add ./src ./res
git commit -m "添加缓存模块"

这个时候有一些改变了没有提交的代码会变红色,在你 切换到master之前,应该暂存当前dev的开发一下到栈里。

git stash


二、合并代码

1.切换到master。 

git checkout master


2.从remote master拉取最新代码到local master。 

admin@ZENGJINLONG2 /d/kuaipan/swap/code/animate/kankananime (dev)
$ git checkout master
Switched to branch 'master'
Your branch is up-to-date with 'origin/master'.

admin@ZENGJINLONG2 /d/kuaipan/swap/code/animate/kankananime (master)
$ git pull
Username for 'http://gitlab.urd.com': zengjinlong
Password for 'http://zengjinlong@gitlab.urd.com':
fatal: Authentication failed for 'http://gitlab.urd.com/kankan/kankananime.git/'


admin@ZENGJINLONG2 /d/kuaipan/swap/code/animate/kankananime (master)
$ git pull
Username for 'http://gitlab.urd.com': zengjinlong
Password for 'http://zengjinlong@gitlab.urd.com':
Already up-to-date.

admin@ZENGJINLONG2 /d/kuaipan/swap/code/animate/kankananime (master)
$


3.切换到dev。 

git checkout dev


4.rebase master 到 dev。 

git rebase master


5.如果有代码冲突,则解决。

三、提交代码

1.切换到master。 

git checkout master


2.将dev的代码合并(merge)到master。 

git merge dev


3.推送(push)local master 到 remote master。 

git push


4.看你心情,保留或者删除dev分支。

回到dev开发,要从stash中取出暂存的状态

git stash pop


总结流程如下:

git clone URL
(master branch now)
git branch dev
(new dev bransh to develop)
git checkout dev
(switch dev bransh now)
(.....coding ..add ... delete..modify...)
git add ./src ./res
(just add src and res in the local reposity)
git stash
(push the status into git stack,as some files modified but not add and committed)
git checkout master
git pull
(update the code from server .)
git checkout dev
git rebase master
(rebase from master.)
(solve the conflict code)
git checkout master
git merge dev
(merge the code from dev)
git push
(upload the new code to server)
git checkout dev
git stash pop
(ok, continue coding ,man )

如果不小心在master分支改动了代码怎么办?

git stash表示的是暂存从上一个commit到现在的改动,一旦你执行了该指令,当前分支会回退到上一次commit时候的状态。所以如果你master改动了。你可以如下处理

git status
(you will the modification is red)
git stash
(temporary store the modification into stack)
git status
(no red file now, as the branch rallback to the latest commit)
git pull
(update the code from the server)
(if you want to save the modification, you need still step on following steps)
git checkout dev
git rebase master
(update the code base on master)
git stash pop
(pop the stored code out)



以EclipseGit插件为例演示

  • 创建Dev分支CreateBranchDevCreateBranchDetail
  • 在marster分支上拉取最新代码PullToMarster
  • 在dev分支上rebase Marster分支代码RebaseFromMarsterToDevRebaseDetail
  • 在Marster分支上合并dev分支代码MergeFromDevToMasterMergeDetail
  • 提交marster分支到远程库PushToRemote

网友评论

登录后评论
0/500
评论
迅雷老曾
+ 关注