使用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插件的使用。html

一,建立Repositorygit

在使用git以前,先建立Remote Repository,用于存储源代码分布式

好比,Remote Repository的URL是 http://xxx/git/git_test工具

二,管理的TargetProjectpost

1,在VS2013中建立Database Project,命名为db_testfetch

2,将DB的Schema同步到Project中url

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

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

三,将Project添加到git Repository.net

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,获取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

相关文章
相关标签/搜索