2012年3月26日月曜日

[项目管理] git 安装与使用

http://www.taocms.org/243.html

0-1. 分布式版本控制工具
0-2. 在一个不能连接网络的地方时, 仍然能够提交文件, 查看历史版本记录, 创建项目分支等
0-3. 仓库所在的目录就是你的日常工作目录, 没有服务器端和客户端之分
0-4. .git目录才是仓库, .git目录外的地方是你的工作目录

1. 安装 git 客户端
$ ./configure --prefix=/usr/local/git1794
$ make
$ sudo make install

2. [可选] 下载并安装 connect.c, 配置 ssh 通过 proxy
$ gcc connect -o connect
$ cat ~/.ssh/config
Host git.postgresql.org
ProxyCommand /home/go/bin/connect -S www.proxy.com %h %p

3. clone
3-1. 上传 /home/.ssh/id_rsa.pub 到 profile, 并且在相应 xxx 项目中登录帐号
     http://www.postgresql.org/community/signup
3-2. clone 代码到本地
$ git clone ssh://git@git.postgresql.org/xxx.git

4. 设置 git 本地用户信息
4-1. /etc/gitconfig 文件: 系统中对所有用户都普遍适用的配置, 若使用 git config 时用 --system 选项, 读写的就是这个文件
4-2. ~/.gitconfig 文件: 用户目录下的配置文件只适用于该用户, 若使用 git config 时用 --global 选项, 读写的就是这个文件
4-3. 工作目录 (当前项目) 中的 .git/config 文件的: 仅仅针对当前项目有效
4-4. 每一个级别的配置都会覆盖上层的相同配置, .git/config 会覆盖 /etc/gitconfig 中的同名变量

$ rm -fv ~/.gitconfig
$ rm -fv ~/.git/config
$ cd ?/git/src
$ sh git_init.sh
$ git config --list ($ git var -l)
$ cat git_init.sh
#!/bin/bash
git config branch.master.rebase true
git config branch.autosetuprebase always
git config user.name "Go"
git config user.email go@gmail.com
git config --global user.name "Go"
git config --global user.email go@gmail.com
# git config --global http.proxy http://www.proxy.com:80
================================================================================
1. 新建项目
$ cd pjname
$ git init

2. 克隆项目镜像到本地
git clone git://github.com/schacon/grit.git
git clone git://github.com/schacon/grit.git mygrit <- 指定新名称

3. 检查当前文件状态
$ git status

4. 更新到本地
$ git pull

5. 提交更改到本地库
$ git commit -m 'comments'

6. 上传至服务器
$ git push

7. 删除文件
$ rm -fv test.txt
$ git rm test.txt
$ git rm log/\*.log <- 删除目录 log 下所有以 .log 结尾的文件
$ git rm \*~ <- 递归删除当前目录及其子目录中所有 ~ 结尾的文件
$ git commit

8. 添加文件
$ git add *.c *.java
$ git commit -m 'add comments'

9. 更新并覆盖本地文件
$ git checkout test.txt

10. 几个 git 地址
[socksify] 有代理服务器时使用 socks 来通信
$ [socksify] git clone git://git.postgresql.org/git/postgresql.git
$ [socksify] git clone git://git.postgresql.org/git/pgpool2.git

0 件のコメント:

コメントを投稿