git

这是什么东西

  • 版本控制软件
  • 分布式的,各个git仓库没有主次之分,你可以在本地分支搞各种事情,做好了传到远程合并
  • 比较灵活,有各种指令需要学习

好处是

  • 分布式,不会太依赖其他分支、网络情况等
  • 比较灵活、强大,开分支超级方便
  • 国内一些比较牛的iOSer都在github之类的平台上share代码,国外的更是,方便学习和fork

碎碎念

安装git

     第一步,先安装homebrew,这里有介绍 http://brew.sh/index_zh-cn.html

ruby -e "$(curl -fsSL <a href="https://raw.github.com/Homebrew/homebrew/go/install)" "="" style="text-decoration: none; color: rgb(92, 230, 56) !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; margin: 0px !important; outline: 0px !important; overflow: visible !important; padding: 0px !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; min-height: inherit !important;">https://raw.github.com/Homebrew/homebrew/go/install)"

   第二步,有了它,可以用来安装git

brew update //更新一下,如果有问题需要 brew doctor一下,然后去fix问题
brew install git
//安装完毕之后,需要 brew link git一下,设置关联

 这个步骤好粗略,详细请看 http://www.moncefbelyamani.com/how-to-install-xcode-homebrew-git-rvm-ruby-on-mac/

 

配置git

git config --global user.name "Your Full Name"
git config --global user.email "Your Email Address"

 

使用git

这里先省略一大部分,clone代码、配置ssh、设置 commit-msg文件等,具体可参考gerrit使用文档

那么使用常用的命令有(以test工程为例)

clone
git clone ssh: //pansy@192.168.4.28:29418/test
 
拉取  fetch
git fetch
 
rebase 以本地拉取到的远程最新commit为base,组织本地commit历史
git rebase origin/master
 
rebase的时候,解决冲突
首先打开冲突文件解决掉冲突,简单来说,就是关注 <<<< ===== >>>>> 这几个东西以及之前的内容
然后 git rebase -- continue 即可。
 
提交代码
git push review
 
-----copy from 网络
提交到缓存区 git add . 当前所有修改提交到缓存区,也可以单独指定
 
git diff 查看当前未缓存的和本地仓库里的区别
 
git diff --stat 显示摘要
 
撤销缓存区里的一个更改,例如hello.rb git reset HEAD -- hello.rb
 
 
git branch 列出可用的分支
 
git branch branchtest 创建branchtest分支
 
git checkout -b branchtest 检查branchtest分支是否存在,不存在就创建,并且切换过去
 
git branch -d branchtest 删除分支branchtest
 
git merge 其它分支合并到当前分支
 
git checkout -b branchtmp origin/branch1 检出并且设置当前分支为远程分支branch1
 
 
git log --oneline //git log --pretty=oneline  一行查看
git shortlog master 生成一个简报
 
 
git tag -a v1. 0 //打上v1.0 tag
 
 
git fetch 下载下来
 
git pull 下载并merge
 
git push remotename branch 推送本地分支branch到远程仓库remotename的branch分支
 
git status //查看状态
我这里的命令相比较介绍文档里面的稍微简单,是因为本地git config做了配置,这里的配置有
[core]
         repositoryformatversion = 0
         filemode = true
         bare = false
         logallrefupdates = true
         ignorecase = true
         precomposeunicode = false
[remote "origin" ]
         url = ssh: //pansy@192.168.4.28:29418/test
         pushurl = ssh: //pansy@192.168.4.28:29418/test
         fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master" ]
         remote = origin
         merge = refs/heads/master
[remote "review" ]
         url = ssh: //pansy@192.168.4.28:29418/test
     receivepack = git receive-pack --reviewer=pansy @kaolafm .com
     push = HEAD:refs/ for /master
         pushurl = ssh: //pansy@192.168.4.28:29418/test
 

 

可以clone一些资料

git clone ssh: //pansy@192.168.4.28:29418/kaolafm-documents

比较不错的git资料如下:

http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值