git xxx

作者: 茗荚小草 | 来源:发表于2017-06-06 17:14 被阅读0次

    A successful Git branching model

    the main branches

    • master
    • develop
    git checkout -b myfeature develop
      --从develop分支新建分支myfeature  
    git checkout develop
      -- 切换到分支develop
    

    Creating a feature brach

    一个新功能的出现,应该创建一个新功能分支,例如myfeature,在该分支上功能开发完毕之后,需要合并到develop上。

    $ git checkout develop  
     Switched to branch 'develop'  
    $ git merge --no-ff myfeature  
     Updating ea1b82a..05e9557
     (Summary of changes)
    $ git branch -d myfeature
     Deleted branch myfeature (was 05e9557).
    $ git push origin develop
    
    
    • --no-ff 参数的作用,确保每次merge都是一次新的commit,避免一个必要的信息的丢失
      ![](/Users/bjhl/Desktop/git /merge-without-ff@2x.png)

    creat a release branch

    release 分支是从develop分支新建来的。新功能开发完毕之后,后续在release分支进入bug fixes阶段(这个阶段不应该给在develop上进行)。release分支一般伴随着版本号,如release-1.2

    $ git checkout -b release-1.2 develop
     Switched to a new branch "release-1.2"
    $ git commit -a -m "version number to 1.2"
     [release-1.2 74d9424] Bumped version number to 1.2
     1 files changed, 1 insertions(+), 1 deletions(-)
    

    bug fixes结束之后,需要将代码merge到master和develop分支(master上每一次merge都是一个版本,伴随着tag)

    $ git checkout master
     Switched to branch 'master'
    $ git merge --no-ff release-1.2
     Merge made by recursive.
     (Summary of changes)
    $ git tag -a 1.2
    
    $ git checkout develop
     Switched to branch 'develop'
    $ git merge --no-ff release-1.2
     Merge made by recursive.
     (Summary of changes)
    

    creat a hotfix branch

    hotfix分支来自于master分支.当线上环境有bug需要修复的时候,需要新建hotfix分支,用来修复bug,hotfix分支一般伴随着版本号,如hotfix-1.2.1。

    $ git checkout -b hotfix-1.2.1 master
     Switched to a new branch "hotfix-1.2.1"
    $ git commit -a -m "version number to 1.2.1"
     [hotfix-1.2.1 41e61bb] Bumped version number to 1.2.1
     1 files changed, 1 insertions(+), 1 deletions(-)
    

    hotfix修完buf完毕之后,也需要将代码同步到master和develop分支。同release分支。

    git 命令

    • git branch -r
      查看远程分支
    • git branch -a
      查看所有的分支,包括远程和本地分支,*表示当前分支

    下面两条命令,表示在当前本地分支合并远程分支

    • git merge origin/master
    • git rebase origin/master

    相关文章

      网友评论

          本文标题:git xxx

          本文链接:https://www.haomeiwen.com/subject/jscnfxtx.html