git学习笔记

本地操作:

首先当然是初始化,执行了这个命令以后当前目录下就会创建一个本地git版本库
$ git init

下面是一个典型的修改-提交过程
do some development
$ git add .
$ git commit

解释一下上面的代码
第一行是通常的开发工作,创建、修改、删除文件什么的
第二行是把当前目录底下所有与上一个版本不同的文件加到commit列表中,如果只想将特定文件进行版本控制的话可以指定add后的参数
第三行是把上一步添加的文件修改提交到版本库

$ git log
$ git blame

分支管理(最有用的):
通常情况下你可以维护两个分支master(默认的)和develop(自己起的名字),master用来保存你的稳定版本,develop用来保存你的开发中版本
一旦你完成了开发中的版本,你就可以将它merge到master分支中
done some development in develop branch
$ git commit -a
$ git checkout master
$ git merge develop
最后一行可以替换为git merge --no-ff develop,这样的好处是保持develop和master独立,后来查看master的历史时就不会看到develop修改的日志,而只有在develop分支的历史中才能看到

在开发过程中可以随时切换分支,就像换个文件夹那么简单,不用担心文件会丢失
developing in develop branch, need to do some change in master branch
$ git commit -a
$ git checkout master
do some development
$ git commit -a
$ git checkout develop
continue to do some development

如果切换时你的当前目录底下有会丢失的内容的话,git会给予警告:

error: Your local changes to the following files would be overwritten by checkout:
xxxx(会丢失的文件)
Please, commit your changes or stash them before you can switch branches.
Aborting

多人协作开发实践:
一个主开发者在github上建立一个项目的版本库,然后将其他人添加为协作者

其他开发者gb,xiaoze...等等配置好Git和GitHub的证书:

将代码库复制到本地
$ git clone XXXX.git

每个开发者创建自己的分支
$ git checkout -b xiaoze

然后在自己的分支上开发
do some development
$ git commit -a
$ git push origin xiaoze

从开发者需要跟随主版本更新的时候:
$ git fetch origin master 首先从远程的origin的master主分支下载最新的版本到origin/master分支上
$ git merge origin/master 合并到当前分支上

查看其他成员更新日志
$ git log

主开发者负责合并从开发者的分支
$ git fetch origin
$ git diff xiaoze
$ git merge xiaoze


参考:
http://log.medcl.net/item/2010/03/git-quick-start/
http://www.ruanyifeng.com/blog/2012/07/git.html
http://www.open-open.com/lib/view/open1328069733264.html
http://www.open-open.com/lib/view/open1328069889514.html


  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值