【玩转Ubuntu】04. Ubuntu上配置git环境


1. 使用PPA安装Git

PPA,表示 Personal Package Archives,也就是个人软件包集。

有很多软件因为种种原因,不能进入官方的 Ubuntu 软件仓库。 为了方便 Ubuntu 用户使用,launchpad.net 提供了 ppa,允许用户建立自己的软件仓库, 自由的上传软件。PPA 也被用来对一些打算进入 Ubuntu 官方仓库的软件,或者某些软件的新版本进行测试。

PPA 上的软件极其丰富,如果 Ubuntu 官方仓库中缺少您需要的某款软件,可以去 PPA 上找找看。


 

#费话不多说,开始安装
bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~$ sudo apt-add-repository ppa:git-core/ppa
bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~$ sudo apt-get update
bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~$ sudo apt-get install git
#查看git的版本
bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~$ git --version
git version 1.8.3.4

 

#根据你的系统语言,git会有相应的版本,我的ubuntu是中文的,所以会有中文版
bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~$ git help
用法:git [--version] [--help] [-c name=value]
[--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
[-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
[--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
<command> [<args>]
最常用的 git 命令有:
add 添加文件内容至索引
bisect 通过二分查找定位引入 bug 的变更
branch 列出、创建或删除分支
checkout 检出一个分支或路径到工作区
clone 克隆一个版本库到一个新目录
commit 记录变更到版本库
diff 显示提交之间、提交和工作区之间等的差异
fetch 从另外一个版本库下载对象和引用
grep 输出和模式匹配的行
init 创建一个空的 Git 版本库或重新初始化一个已存在的版本库
log 显示提交日志
merge 合并两个或更多开发历史
mv 移动或重命名一个文件、目录或符号链接
pull 获取并合并另外的版本库或一个本地分支
push 更新远程引用和相关的对象
rebase 本地提交转移至更新后的上游分支中
reset 重置当前HEAD到指定状态
rm 从工作区和索引中删除文件
show 显示各种类型的对象
status 显示工作区状态
tag 创建、列出、删除或校验一个GPG签名的 tag 对象
命令 'git help -a' 和 'git help -g' 显示可用的子命令和一些指南。参见
'git help <命令>' 或 'git help <指南>' 来查看给定的子命令帮助或指南。

 

 

2. ubuntu安装ssh

ubuntu默认并没有安装ssh服务,如果通过ssh链接ubuntu,需要自己手动安装ssh-server。判断是否安装ssh服务,可以通过如下命令进行:

 

 

bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~$ ssh localhost
ssh: connect to host localhost port 22: Connection refused
#出现上面的结果就是没有安装喽,下面安装一下
bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~$ sudo apt-get install openssh-server

 

3. 创建验证用的公钥

 

 

#1. 用你的邮箱创建一个ssh key
ssh-keygen -t rsa -C "xiaopeng.bxp@*******.com" # Generating public/private rsa key pair...cat ~/.ssh/id_rsa.pub# ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC6eNtGpNGwstc....


#2. 新增一个SSH key
打开github或gitlab,在SSH Keys里新建一个SSH Key,复制~/.ssh/id_rsa.pub中的内容放到SSH key,保存就可以了。

#尝试从gitlab上把代码clone下来
bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~/workspace2$ git clone http:*********
正克隆到 'spark'...
Username for 'http://gitlab.****.com': xiaopeng.bxp
Password for 'http://xiaopeng.bxp@gitlab.***.com': 
fatal: Authentication failed for 'http://gitlab.alibaba-inc.com/sospartan/spark.git/'
#哎哟我去,需要输入用户名和密码,说明我们ssh key没有配对,或者我们下载地址不对。尝试改一下
# 设置完毕后再次执行clone命令
bixiaopeng@bixiaopeng-To-be-filled-by-O-E-M:~/workspace2$ git clone http://gitlab.***.com/sospartan/spark.git
正克隆到 'spark'...
remote: Counting objects: 7778, done.
remote: Compressing objects: 100% (5044/5044), done.
remote: Total 7778 (delta 4649), reused 3891 (delta 2186)
接收对象中: 100% (7778/7778), 7.46 MiB | 9.75 MiB/s, done.
处理 delta 中: 100% (4649/4649), done.
Checking connectivity... done


成功!! 

 

 

posted @ 2013-08-23 19:35  pangbangb  阅读(542)  评论(0编辑  收藏  举报