1.SourceTree 是什么?(概念)
- SourceTree 是 Windows 和Mac OS X 下免费的 Git 和 Hg 客户端,拥有可视化界面,容易上手操作。同时它也是Mercurial和Subversion版本控制系统工具。支持创建、提交、clone、push、pull 和merge等操作。
- 特点:分布式
![]()
- 优点:就是当前写完了代码, 提交到本地仓库后, 不用害怕丢失, 而且也可以做版本的记录, 如果将来有一天想找回几天前的代码, 也是可以的.
- 备注:代码的合并是从远程仓库拉取下来别人新写的代码, 然后在本地仓库进行合并(以及如果有冲突由程序员解决)
2. Git 部分名词解释(各种操作解释)
1.克隆(clone):从远程仓库URL加载创建一个与远程仓库一样的本地仓库
2.提交(commit):将暂存文件上传到本地仓库(我们在Finder中对本地仓库做修改后一般都得先提交一次,再推送)
3.检出(checkout):切换不同分支
4.添加(add):添加文件到缓存区
5.移除(remove):移除文件至缓存区
6.暂存(git stash):保存工作现场
7.重置(reset):回到最近添加(add)/提交(commit)状态
8.合并(merge):将多个同名文件合并为一个文件,该文件包含多个同名文件的所有内容,相同内容抵消
9.抓取(fetch):从远程仓库获取信息并同步至本地仓库
10.拉取(pull):从远程仓库获取信息并同步至本地仓库,并且自动执行合并(merge)操作,即 ** pull=fetch+merge **
11.推送(push):将本地仓库同步至远程仓库,一般推送(push)前先拉取(pull)一次,确保一致
12.分支(branch):创建/修改/删除分枝
13.标签(tag):给项目增添标签
14.工作流(Git Flow):团队工作时,每个人创建属于自己的分枝(branch),确定无误后提交到master分枝
15.终端(terminal):可以输入git命令行
3. Sourcetree的具体使用

1.第一步:安装Sourcetree
(1)图标:
(2)不建议在appstore直接搜索下载SourceTree,因为appstore里的版本已经十分老旧(好像是2012年更新的)。建议前往官网下载安装最新版,这里提供一个SourceTree for Mac V2.0.5.2的百度云的方便链接。 传送门→SourceTreeDownload 或者http://pan.baidu.com/s/1sjWOn9b
(3)如果看到下面这个界面就说明安装成功

备注:因为正版SourceTree要收费,一般使用的是破解版,存在一个时间段,如果过期了,则需要登录sourcetree重新下载license许可证,导入即可再继续使用




2.以开源中国为例作为服务器代码托管(建立远程仓库)
(1)先注册开源中国,然后登录,拉到最下面点友情链接的第三个“码云”

或者直接戳这http://git.oschina.net 然后注册登录,界面如下:


然后会给你注册时候的邮箱,发送一个验证邮件,注册一下

然后点击链接,会跳转到主页

备注:已注册的童鞋忽略这一步
(2)创建项目
如果你是项目的创始人(小红), 那么你就点击项目(进行创建)
- 第一步, 创建项目


- 项目创建成功, 如下图

- 因为我创建的私有项目(如果是私有项目, 则执行下面这步, 如果不是则略过下面这步(步骤3.x))
(3.1)点击右上角管理

(3.2)点击添加项目成员, 我这里另一个(小明)是lidongxu_work@126.com

这里说一下:
管理员: 最高权限
开发者: 可以上传或者克隆(下载)代码 (一般给予这个权限)
观察者: 只能下载, 无法上传
报告者: 只能看, 和评论, 什么也不能干!
(3.3)输入对方oschina邮箱账号, 然后给予权限

回到项目首页(注意是点你的项目, 例如我这里是a1209woshi)

3.建立本地代码仓库
- 获取克隆的网址(给别人使用, 让别人可以用这个网址, 把对应的远程仓库东西克隆(下载)到本地)
我这里获取到的是 https://git.oschina.net/women2323/a1209woshi.git

- 回到SourceTree, 新建本地仓库

填写克隆URL地址如果是第一次使用SouceTree(并且是私人项目), 会弹出让你输入你的oschina账号和密码

备注:这个地方容易出错,需要注意一下,检查是否填写的账号是正确的,账号一般填注册远程仓库的邮箱,如图示例:




登录成功之后以下克隆的按钮就可以点击创建了,否则不能点击(公有的不用登录,可以直接创建克隆)


- 上传项目到远程仓库(供别人(小明)下载)
(3.1) 找到本地仓库文件夹(我的在桌面)

(3.2) 然后看工作区有变化, 然后把未暂存文件, 放入已暂存文件区中


(3.3) 这里说一下, Git的工作原理图

(3.4) 然后commit(提交)到本地仓库分支中



(3.5) 养成一个好习惯, 先从远程仓库拉去一下, 然后在本地合并好了, 然后再推送回到远程仓库中, (也就是说, 合并代码是在本地进行的) (注: 如果你不拉取, 很容易把别人刚提交的代码, 顶掉)


(3.6) 回到网页上去看看, 刷新下, 会看到我刚传的项目

- 别人如何拉取这个项目, 把HTTPS克隆网址给他(如果是私有项目, 请确定把对方oschina账号添加到你的项目中了)
(4.1) 同样, 从URL克隆(新建本地仓库)

(4.2) 然后填入克隆网址, 然后选择本地仓库位置

(4.3) 进入到工作区之后, 因为我是要克隆代码从远程仓库到本地, 所以直接点击拉取

(4.4) 你会惊奇的发现, 本地仓库里, 已经有了远程仓库的东西啦!!(以后再写好代码, 只需要执行第6步)就可以了, 这样就可以方便和别人进行团队协作开发了)
4.Sourcetree工作界面操作的补充
以下展示界面为例:

1.左上角工作副本:
即本地仓库的工作区,在这当中可以看到修改了那些文件,在哪个地方改的2.左边的分支:
这里展示的即本地仓库的分支;master是总分支,2.6.1wzx_dev是表示租车这个分支,wzx_dev是医疗直通车的分支...3.左边的远端是远程仓库:
可以看到另外两个小伙伴的远程仓库分支4.一般先把工作副本的东西提交,提交到本地的当前分支的缓存区;然后抓取所有远端(拉取是抓下所有分支并且直接合并),然后再合并(有时会出现冲突,使用工具Araxis Merge解决)相对应想合并的分支,最后再推送到自己在服务器(如在开源中国上已经创建好的远程仓库)上的远程仓库
5.目录的分支中创建新分支
6.代码回滚


source tree传到GitHub:http://www.jianshu.com/p/be9f0484af9d
相关链接:https://www.jianshu.com/p/70d8dafd4b55
网友评论
求指教!!!
git push
输入账号,以及修改后的密码;
remote: HTTP Basic: Access denied
fatal: Authentication failed for 'https://XXXXXXXXXXXXXXX.git/'
Pushing to https://xxxxxxx_qq.com_xxxxxxx@xiaolvyun.baidu.com/git/xxxxxxx/test/.git
XML error: no element found
error: no DAV locking support on https://xxxxxxx_qq.com_xxxxxxx@xiaolvyun.baidu.com/git/xxxxxxx/test/.git/
fatal: git-http-push failed
error: failed to push some refs to 'https://xxxxxxx_qq.com_xxxxxxx@xiaolvyun.baidu.com/git/xxxxxxx/test/.git'
Completed with errors, see above
第二个是:删除已经不在跟踪的分支
第三个是:抓取所有本地分支,就是自己所建立的所有分支