GitHub和SourceTree入门教程 - 冰冻火山 - 博客频道 - CSDN.NET
    Friday, May 20, 2016
    5:39 PM
    GitHub和SourceTree入门教程
    .
    标签: sourcetreegithubsourcetree教程sourcetree使用
    2014-09-14 01:12 142145人阅读 评论(28) 收藏 举报
    .
    本文章已收录于:
    计算机生成了可选文字:
    Git知识库
    GitHub和SourceTree入门教程 - 冰冻火山 - 博客频道 - CSDN.NET - 图2
    分类:
    Java(13)
    GitHub和SourceTree入门教程 - 冰冻火山 - 博客频道 - CSDN.NET - 图3
    .
    版权声明:本文为博主原创文章,未经博主允许不得转载。
    —>本教程适用于主流的开源网站github和bitbucket,个人认为sourceTree还是比较好用的git客户端,支持windows和mac os。
    —>soureceTree的最新版本可能与此教程的screenshot有些许不同,但大同小异(sourceTree的最新版本操作上更人性化)
    —>大家可以先看个关于git工作流程的视频,先了解一下,被youku转码了,不太清楚,将就看吧,点这里
    —>在github上注册一个账号,然后登陆。
    —>在github上点击create new, new repository, 随便输入一个项目名称即可,注意选上init this repository with readme(不选择也可以,事后再自己编辑),如下图。
    关于git流程,给个不错的参考链接,点我打开
    计算机生成了可选文字: Owner  collonn •  Re sito name  / My8atisGen  Name already exists on this account  Great repository names are short and memorable. Need inspirationo How about massive-octo-cyril.  Description (optional)  http://blog. csdn. net/ collonn  P ublic  Anyone can see this repository. You choose who can commit.  Private  You choose who can see and commit to this repository  41 Initialize this repository with a README  This will allow you to git clone the repository immediately. Skip this step ifyou have already run sit init locally  Add gitignore: None  o  Add a license: None
    —>如果想删除刚创建的项目,可以,点右下角的setting,如下图。
    计算机生成了可选文字: Description  Website  Short description of this repository  Website for this repository (optional)  og„ cs  n. ne  Save or Cancel  contributor  G) 1 commit  branch  master •  Initial commit  V 1 branch  MySatisGen / +  O releases  collonn authored 2 hours ago  e README.md  README.md  MyBatisGen  latest commit eS379bcb2ø  Initial commit  p:  2 hours ago  co  onn  O Code  O Issues  n Pull Requests  Wiki  pulse  Graphs  Settings  HTTPS clone URL  https://github.con  You can clone with HTTPS,  o  SSH, or Subversion.  Clone in Desktop  Download ZIP
    —>将页面拉到最下边,点击delete this repository,在弹出层中输入项目名称,点击删除即可,如下图。
    计算机生成了可选文字: GitHub Issues adds lightweight issue tracking tightly integrated with your repositor•
    —>现在要在本地clone出远程的项目,在github上点击刚才创建的项目,进行项目详情,在右下角有一块信息,复制https连接,如下图
    计算机生成了可选文字: collonn I MyBatisGen  Description  Short description of this repository  Website  Website for this repository (optional)  O releases  Unwatch  Save or Cancel  contributor  Star  O Code  O Issues  n Pull Requests  Wiki  pulse  Graphs  Settings  HTTPS clone URL  Fork  G) 1 commit  branch  master •  Initial commit  V 1 branch  MySatisGen / +  collonn authored 2 hours ago  e README.md  README.md  MyBatisGen  latest commit eS379bcb2ø  Initial commithttp : /  csdn„ net/ collonn  2 hours ago  https : / /github. con  You can clone with HTTPS,  SSH, or Subversion  Clone in Desktop  Download ZIP
    —>在本地随便一个目录下,输入以下命令,git clone https://github.com/collonn/MyBatisGen.git,(这里用了一个我的开源项目做为示例),
    —>我们可以看到,新建的项目除了一个readme文件,什么也没有,你可以随便将一个maven项目的内容copy到此目录下,编译正确后,就可以提交了,下面我们以SourceTree为例,来演示怎么用可视化GUI工具提交修改。
    —下载并安装SourceTree,以windows版本为例,安装完成后,打开sourcetree,如下图
    计算机生成了可选文字: SourceTree  File Edit View Repository Actions 1001s Help  Clone / New  Commit Checkout Discard  Stash  Add  Remove Add/Remove  Fetch  Push  Branch  Merge  Tag  Git Flow  Terminal  Setti ngs  http://blog- csdn. net/ collonn
    —>点击file-open,选择我们刚才clone出来的项目的根目录后,打开后,如下图,可以看到,branches只有一个master, 点击右边的Uncommited changes,会显示你所有有改动但未提交的文件。
    计算机生成了可选文字: SourceTree  file Edit View Repository Actions 1001s Help  Clone / New Commit Checkout  Di sca rd  Stash  Add  Re move  Ad d/ Re move  Fetch  pull  Push  Bra nch  Merge  Tag  Git Flow  My8atisGen  File Status  @Working Copy  Branches  Tags  Remotes  orgn  Show Remote Branches Date Order  Terminal  14 2014 0:35  13 2014 22:4  Setti ng s  Jump to:  Commit  e5379bc  Graph  uncommitted changes  origin/ master  origin/HEAD  Pending files, sorted by file status •  C\] Staged files  C\] Unstaged files  C\] MyBatisGen.iml  00  ta rget/classes/ftl / model.ftl  00  ta rget/classes/ftl / ma pper.ftl  ta rget/cla sses/ftl 'common.ftl  File Status Log / H i story Search  Description  master Initial commit  Author  collonn <collonn  http : // blog.  csdn. net/ collonn  MyEatisGen.imI  File Contents  Search  Stage hu  Oxml  •:mdule org.jetbrains.idea.maven.project.MavenPr05ectsManager.ism  (component  (output DRS/ target/classes (output-test DIPS/ target/ test-classes” (content (sourceFoIder (sourceFoIder (sourceFoIder (sourceFoIder (excludeFoIder / content> •:orderEntD’ type” inheritedJdk” / > DIRS/src/main/resource” ty DIRS/src/test/resource” ty DIRS/src/main/5ava” isTes DIRS/src/test/5ava” isTes DIRS/target” (orderEntD’ / > (orderEntD’ type” library” scope” TEST” junit:juni Atlassian Clean 28 master” class=”align-none”>
    —>看Unstaged files这一块内容,我们按住shift,选择所有你要提交的文件,然后再点鼠标右键,选择add(意思就是add到本地的索引库),操作完成后,Staged files这块内容就会出现我们刚才选择的所有文件,如下图
    计算机生成了可选文字: SourceTree  File Edit View Repository Actions 1001s Help  Clone / New Commit Checkout Discard  Stash  Add  Re move  Ad d/ Re move  Fetch  pull  Pus h  1.9  Bra nch  Merge  ag  Git Flow  My8atisGen  File Status  @Working Copy  Branches  Tags  Remotes  origin  Show Remote Branches Date Order •  Terminal  14 2014 0:38  13 2014 22:4  Setti ngs  Jump to:  Commr  e5379b(  Graph  uncommitted changes  origin/ master  origin/HEAD  Pending files, sorted by file status •  ed files  MyBatisGen.iml  ta rget/classes/ftl/mapper.ftl  ta rget/cla s ses/ftl 'common.ftl  ta rget/cl a s ses/config.properties  Unstaged files  Description  master Initial commit  Author  collonn <collonn  http : // blog.  csdn„ net/ collonn  MyEatisGen.imI  File Contents  Oxml  Search  Q.  Unstage hu nk  •:mdule org.jetbrains.idea.maven.project.Mavenprojectsmanager.ismave  (cornponent  (output / >  (output-test //SÆOULE_DIRS/target/test-cIasses (orderEntN,’ type” inheritedJdk” / > DIRS/src/main/resource” ty DIRS/src/test/resource” type isTestSo DIRS/src/test/5ava” isTestSo 01%/ target” / >” class=”align-none”>
    —>在我们提交到本地repo前,我们先在sourcetree中设置一下通用information,当commit到本地时,这个infomation会当做通用的提交信息,点击tool->options,在full name和email address中输入你的github账号信息,如下图
    计算机生成了可选文字: SourceTre e  File Edit View Repository Actions  Clone / New Commit Checkout Discard  Options  General  Diff  Mercu rial Custom Actions Authentication  Networ  MyBatisGen  File Status  @Working Copy  Branches  Tags  Remotes  origin  Allow SourceTree to modi6/ your global Git and Mercurial config files  Full Name: xxx  Pending files, sorted  Staged files  src/main/reso  Email addr  @126  SSH Client Configuration  SSH Key:  SSH Client: PuTTY / Plink • (Git only, Mercurial always uses Plink on Windows)  Automatically start SSH agent when SourceTree opens  Misc  Project folder:
    —>返回到我们刚才那一点,在Staged files中选择要提交到本地仓库的文件后,点击sourcetree左上角的commit之后,会让我们输入comments about this commit,输入后,点提交,可能会提示你再输入github的用户名和密码,如下图
    计算机生成了可选文字: ource  File Edit  Clone / N  Commit  •tory Actions 1001s Help  heckout Discard Stash  Add Remove  Ad d/ Re move  Fetch  pull  Push  1.9  Bra nch  Merge  Tag  Git Flow  MyBatisGen  File Status  @Working Copy  Branches  Tags  origin  Pending files, sorted by file status  @ Staged files  4\] src/main/resource/readme.txt  Unstaged files  ta a rea d me.txt  collonn <collonn@126.com>  ode refactori  target/classes/ read me.txt  Hunk I: Lines 14  - need help,  you  -->anything need help,  qq: 19S3S838S  enail : collonn@126.com  Terminal  Search  can contact me:  contact me via:  http . • csdn„ net. collonn  Setti ng s  Commit optionsm  C\] Push changes immediately to origin/master  File Status Log / History Search  Commit Cancel  Atlassian  02 *master
    —>至此,我们只是提交到了本地仓库,最后一步就是如提交到远程仓库了,点击工具栏的push按钮,就可以提交到远程仓库(push到远程前,最好先从远程pull一把)。点击pull,即可从远程仓库下载最新的别人提交的修改了,如下图
    计算机生成了可选文字: SoGrceTree  File Edit View Repository Actions 1001s Help  Clone / New Commit Checkout Discard  Sta sh  Add  Remove Add/Remove  Fetch  pull  Branch  Merge  Tag  Git Flow  My BatisGen  File Status  [Working ](/Working ) Copy  Branches  master  Tags  Remotes  origin  Show Remote Branches Date Order •  Graph  uncommitted changes  code refactor  I ahead  master  Description  MyBatisGen code refactor  Initial commit  http : //blog. csdn. net/ collonn  Term na  Date  14 2014 1:05  14 2014 1:05  14 2014 0:51  13 2014 22:4  Author  collonn <collonn  collonn <collonn  collonn <collonn  Setti ngs  Jump to:  Commit  542adeü  654eIdI  e5379bc  Q.  Pending files, sorted by file status  [Z] Staged files  Search  target/classes/ readme .txt  Hunk I Lines 14  - - >anything need help,  -->anything need help,  you  c an  contact  Discard hu n k  contact me:  me Via:
    —>点击push后,会让你选择提交到远程仓库的哪个分支,自己决定吧,提交到远程仓库后,github上就可以看到你提交的内容了,如下图
    计算机生成了可选文字: branch  master •  My BatisGen code refactor  MySatisGen +  collonn authored 24 minutes ago  latest  src  target/classes  My8atisGemiml  e README.md  e pom.xml  README.md  My BatisGen code refactor  My BatisGen code refactor  My BatisGen code refactor  http://blog. csdn„ net/ collonn  Initial commit  My BatisGen code refactor  MyBatisGen
    —>在分支1上的修改可以通过cherry pick,直接将修改的代码commit到分支2上。
    也可以在分支2上去过merge操作来获取其它分支的commit,但是要通过intellij idea去进行merge。
    注意cherry pick只用直接取到你本次提交的代码,另人在你提交之前的提交不会搞过来,而merge则会把你提交前别人提交也也搞过来。
    intellij ide操作如下图:
    计算机生成了可选文字: Changes:  Local  Default  (2 f/es)  @ README. md  Thumbs.db  Commit Changesm  Revertm  Move to Another Changelist  Show Diff  Jump to Source  Commit Filem  + Add  An notate  Show Current Revision  Ctrl+Alt+A  8 ra nchesm  Ctrl+D  9: Changes  errors minu  x  Terminal  es no)  http://blog. cs  Delete  Compare with the Same Repositoru Version  Compare with Latest Repository yersion  Compare withm  Il • v1vi1fK@rÅJnchm  Show History  Show History for Selection  Revertm  Resolve Conflicts...  Repository  UnStash Changesm  Reset HEADm  Create Patchm  Shelve Changesm  Refresh  Local Histo  Ctrl+F5  Fetch  Pushm  Reba sem  Ctrl+Shift+K  Spring  6: TODO  Auto make comoleted WI
    —>sourcetree左边栏的Branches,可以随便删除,再重新从Remotes中选择你要check out的分支,clone到本地仓库。
    —>对于当前的所有本地改动,都可以用Stash功能将改动暂时保存,在任何时候都可以进行apply stash to current work branch。
    —>至此,githut和sourcetree的使用,就结束了,工具只是方便大众化,不排斥只用command line操作,自己玩吧。。。
    .

    30

    3
    .


    上一篇Apple Swift 中文教程 快速参考 基本语法
    下一篇jQuery-DesktopGrid
    .
    我的同类文章
    Java(13)

    更多文章
    已使用 Microsoft OneNote 2016 创建。