zl程序教程

您现在的位置是:首页 >  其他

当前栏目

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

流程团队企业Git开发 协同 一般 使用
2023-09-14 08:56:49 时间
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/


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
快速上手git单人开发 你好看官,里面请!今天笔者讲的是单人开发快速上手git。不懂或者觉得我写的有问题可以在评论区留言,我看到会及时回复。 注意:本文仅用于学习参考,不可用于商业用途,如需转载请跟我联系。