• Git 第四篇:使用VS2013和git进行代码管理


    git是一款非常流行的分布式版本控制系统,使用Local Repository追踪代码的修改,通过Push和Pull操作,将代码changes提交到Remote Repository,或从Remote Repository中获取代码的最新版本,实现团队源代码的共享和管理。VS2013 集成了git插件,能够使用git进行源代码管理,比如:Merge Branch,Code Review,Code Changes的Push和Pull等,这里简单介绍一下VS2013中git插件的使用。

    一,创建Repository

    在使用git之前,先创建Remote Repository,用于存储源代码

    比如,Remote Repository的URL是 http://xxx/git/git_test

    二,管理的TargetProject

    1,在VS2013中创建Database Project,命名为db_test

    2,将DB的Schema同步到Project中

    选中Project,点击-》Schema Compare,弹出一下窗口

    • 左边是源(Source),右边是Target,执行Compare,将Source(DB)和Target(Project)进行比较;
    • 点击Update,更新Target;

    三,将Project添加到git Repository

    1,将Project添加到源代码管理

     

    2,选择源代码管理 git

    第一个选项是TF 版本控制,第二个选项是Git,选择Git。

    四,切换到Team Explorer

    1,点击Home菜单,如果是初次使用,会提示“Install 3rd-party Git command prompt tools”,点击“install”,按照 git 命令行工具。

    在Project下面有Changes,Branches,Unsynced Commits 和 Settings 选项,使用这些选项对Project进行管理

    五,管理Local Branch

    1,点击Branches选项,点击New Branch,在Local Repository中创建Branch

    2,合并Branch(Merge Branch)

    3,发布Branch(Published Branches)

    • Unpublished Branches :列出在Local Repository中创建的所有Branches
    • Published Branches :列出已经发布到Remote Repository的Branches

    六,管理Changes

    1,点击Changes选项

    初次使用,会提示“Configure your user name and email address before committing changes”,输入Name 和 Email即可,这些配置信息,能够通过“Settings”选项查看。

    2,提交修改

    修改的提交(Commit) 有三种方式:

    • Commit:提交到Local Repository
    • Commit and Push:提交到Local Repository,并推送(Pull)到Remote Repository
    • Commit and Sync:提交到Local Repository,并同步(Sync)到Remote Repository

    3,提交到特定的Branch

    Branch选择db_test,点击Commit

    4,修改已经提交到Local Repository,该Commit并没有Push 或Sync

    5,未同步提交(Unsynced Commits)

    点击"Unsynced Commits"选项,初次使用,需要输入Remote Repository的URL

     

    6,发布到Remote Repository

    输入Remote Repository的URL,点击Publish,将提交到Local Repository的Commit,同步到Remote Repository

     

    七,管理代码同步

    在“Unsynced Commits”选项中,能够对当前的Branch进行代码Changes的Fetch,Pull,Push操作。Unsynced Commits 的含义是指Local Repository没有同步到Remote Repository,也指Remote Repository没有同步到Local Repository,因此,Sync 按钮的作用是Pull 和 Push的封装。

    1,获取当前Branch的最新版本(Incomming Commits)

    Fetch 和 Pull 都是从当前Branch获取代码的最新版本,但是Pull和Fetch是有区别的:Pull=Fetch+Merge:

    • Pull :下拉远程分支并与本地分支合并,git Pull会将Local Branch更新至Remote Branch的最新状态;
    • Fetch:只是下拉远程分支,不会自动执行Merge操作;

    当Remote Repository中有Incomming Commits时,推荐使用git Pull来获取当前Branch的最新版本。

     

    2,将代码修改Push到Remote Repository(Outgoing Commits)

    当存在Unsynced Commits时,通过git Push,将提交到Local Repository的代码Changes同步到Remote Repository。

    八,发布Branch

    必须配置Remote Repository之后,才能发布Branch,将Local Branch发布到Remote Repository。

    操作步骤:在“Branches”选项中,从“Unpublished Branches”列表中选择Branch,点击右键,选择“Publish Branch”,将该Branch发布到Remote Repository中。

    九,创建Code Review请求

    在TFS中,能够将代码的changes发送到同事,请求对代码进行审查(Code Review),在git中,也能实现Code Review,不过,名称叫做Pull Request,VS2013中的git插件,不能创建Pull Request,必须通过Web客户端来创建Pull Request。

    创建Pull Request的流程是:

    1,首先将Branch发布到Remote Repository,即Publish Branch

     

    2,创建Pull Request

    点击"Create a pull request",创建Pull Request

    3,输入Reviewers,并关联Work Items

    注意,Pull是把Brach和其他Brach进行合并,必须注意要合并的Target Branch。

    十,克隆Repository

    使用git clone命令,获取Remote Repository中代码的最新版本

    点击"Connect to Team Projects",输入Remote Repository的URL,将Remote Repository复制到Local Repository中。

    参考文档:

    vs2013 git 使用总结

    使用GIT进行源码管理 —— 在VisualStudio中使用GIT

    git fetch和git pull之间的区别

    Git 少用 Pull 多用 Fetch 和 Merge

  • 相关阅读:
    Git 生命周期
    Git 配置环境
    JAVA克隆对象报错:The method clone() from the type Object is not visible
    C# 将字符串按要求分解成字符串数组
    servlet 标红的错误笔记
    TIBCO Jaspersoft Studio 报表软件使用教程
    错误笔记4
    ^按位运算详解
    表现层状态转换
    servlet 读取文件
  • 原文地址:https://www.cnblogs.com/ljhdo/p/5048992.html
Copyright © 2020-2023  润新知