Skip to content

Instantly share code, notes, and snippets.

@dontcry2013
Last active May 3, 2019 04:27
Show Gist options
  • Save dontcry2013/f43933808bc1855d55a37d35ffd69ccd to your computer and use it in GitHub Desktop.
Save dontcry2013/f43933808bc1855d55a37d35ffd69ccd to your computer and use it in GitHub Desktop.
git branch practice

git建议操作流程

此建议操作流程以真实开发过程为例(Student Service)

新建本地test分支

  1. 首先查看本地和远端的分支
DEVs-MBP:ss devmac$ git branch -avv

  master               0f7de684 [web/master] 恢复app/View/Elements/addDocumentChecklist.ctp

  teaching             019cfe69 add academic router again

* temp                 0f7de684 恢复app/View/Elements/addDocumentChecklist.ctp

  remotes/web/master   0f7de684 恢复app/View/Elements/addDocumentChecklist.ctp

  remotes/web/teaching 5166a983 Merge branch 'master' of 114.112.104.200:/aemg/repo/service
  1. 新建本地分支,此分支用于本地开发测试使用,不提交到远端。
DEVs-MBP:ss devmac$ git branch test
  1. 再次运行,看是否新建分支成功
DEVs-MBP:ss devmac$ git branch -avv

  master               0f7de684 [web/master] 恢复app/View/Elements/addDocumentChecklist.ctp

  teaching             019cfe69 add academic router again

* temp                 0f7de684 恢复app/View/Elements/addDocumentChecklist.ctp

  test                 0f7de684 恢复app/View/Elements/addDocumentChecklist.ctp

  remotes/web/master   0f7de684 恢复app/View/Elements/addDocumentChecklist.ctp

  remotes/web/teaching 5166a983 Merge branch 'master' of 114.112.104.200:/aemg/repo/service

切换到test分支,进行开发工作

DEVs-MBP:ss devmac$ git checkout test

Switched to branch 'test'

查看日志,可以看到test,temp,master和远端master分支代码版本是一致的

DEVs-MBP:ss devmac$ git log

commit 0f7de684831fa3b41028405dd402ac73fe89005a (HEAD -> test, web/master, temp, master)

Author: Zach <[email protected]>

Date:   Fri May 3 09:40:37 2019 +1000

    恢复app/View/Elements/addDocumentChecklist.ctp

开发完成,提交到本地暂存起来,切换回master分支并合并

  1. 填写备注,存储在test分支
DEVs-MBP:ss devmac$ git commit -am '添加、修改session time成功后自动跳转到teachingbranchcalendar index'

[test 763e2c75] 添加、修改session time成功后自动跳转到teachingbranchcalendar index

 2 files changed, 2 insertions(+), 5 deletions(-)
  1. git log可以看到,test分支已经比其他分支多了一个commit
DEVs-MBP:ss devmac$ git log

commit 763e2c75827b071e4ec5518b5baf15a53bae5068 (HEAD -> test)

Author: Zach <[email protected]>

Date:   Fri May 3 14:04:59 2019 +1000

    添加、修改session time成功后自动跳转到teachingbranchcalendar index

commit 0f7de684831fa3b41028405dd402ac73fe89005a (web/master, temp, master)

Author: Zach <[email protected]>

Date:   Fri May 3 09:40:37 2019 +1000

    恢复app/View/Elements/addDocumentChecklist.ctp
  1. 切换到master分支,准备发布
DEVs-MBP:ss devmac$ git checkout master

Switched to branch 'master'

Your branch is up to date with 'web/master'.

DEVs-MBP:ss devmac$ git merge test

Updating 0f7de684..763e2c75

Fast-forward

 app/Controller/TeachingBranchSessionTimesController.php | 2 +-

 app/Model/TeachingClassroom.php                         | 5 +----

 2 files changed, 2 insertions(+), 5 deletions(-)
  1. 确定master分支和test分支代码是一致的
DEVs-MBP:ss devmac$ git log

commit 763e2c75827b071e4ec5518b5baf15a53bae5068 (HEAD -> master, test)

Author: Zach <[email protected]>

Date:   Fri May 3 14:04:59 2019 +1000

    添加、修改session time成功后自动跳转到teachingbranchcalendar index

commit 0f7de684831fa3b41028405dd402ac73fe89005a (web/master, temp)

Author: Zach <[email protected]>

Date:   Fri May 3 09:40:37 2019 +1000

    恢复app/View/Elements/addDocumentChecklist.ctp
  1. 拉去远端分支代码
DEVs-MBP:ss devmac$ git pull web master 

Enter passphrase for key '/Users/devmac/.ssh/id_rsa': 

From 114.112.104.200:/aemg/repo/service

 * branch              master     -> FETCH_HEAD

Already up to date.

DEVs-MBP:ss devmac$ git push web master

Enter passphrase for key '/Users/devmac/.ssh/id_rsa': 

Enumerating objects: 13, done.

Counting objects: 100% (13/13), done.

Delta compression using up to 4 threads

Compressing objects: 100% (7/7), done.

Writing objects: 100% (7/7), 702 bytes | 702.00 KiB/s, done.

Total 7 (delta 6), reused 0 (delta 0)

remote: Already on 'teaching'

To 114.112.104.200:/aemg/repo/service.git

   0f7de684..763e2c75  master -> master
  1. 重新切换回test分支,合并此前拉去的master分支代码,并在test分支上做后续开发
DEVs-MBP:ss devmac$ git checkout test

Switched to branch 'test'

DEVs-MBP:ss devmac$ git merge master

Already up to date.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment