Git 使用教程
- Installation
1.1 git installation in linux
http://git-scm.com/downloads download sw package
$tar -zxvf git-1.8.5.tar.gz
$cd git-1.8.5
$./configure
$make
$sudo make install
1.2 git installation in windows
msysgit是 Windows版的Git ,从http://msysgit.github.io/ 下载,然后按默认选项安装即可。安装完成后,在开始菜单里找到 “Git”->“Git Bash” ,蹦出一个类似命令行窗口的东西,就说明 Git安装成功!
- git configuration
$git --version
$git config --global user.name "xiaopili"这里用你的用户名
$git config --global user.email " [email protected] "这里用你的邮箱
◎本地与git远程仓库间传输是通过SSH加密的话,需要创建SSH key.
[[email protected] ~]# ssh-keygen -t rsa -C "[email protected]"这里用你的邮箱(这里相当于设置你的密码)
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
6c:59:8d:e9:ed:f6:ee:6d:fc:c4:22:d5:2d:83:48:da [email protected]
[[email protected] ~]# cat /root/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAsqPwmzVK0Pmmi4RLjFxMOeveGIRi8qdHpqxz7hBDRQP+KcIdp9LhqaCiTDXpyCr7wbnjtnzBfykbsdj4sRoAWagvYMY5TqMCmCLurjaaCmU9E2B+nMCCmr9n8AmeTOf7qQHUtM1ZQKc0lT8RZVkwkhP
1tcAz8g045oyon1FM2lsUzmFYzqfKhk6NhXYxaIf4ONW0FhrSv+xO8VAiYF7B42uVyGnbNbwUxHLWPIGb9Sqcn0Kog2vJYn0n3oT8QukPNFrT3zg3oFFBTa0mVG2CtymIVdl1FGtUv+rWGPd0N7glPFZ7GU8dl7Kci3hssFnW17+Z6GKQIHOKgVga14
OHZw== [email protected]
Add to http://hzgitv01.china.nsn-net.net/#/settings/ssh-keys
$ curl -o .git/hooks/commit-msg http://hzgitv01.china.nsn-net.net/tools/hooks/commit-msg
$ chmod u+x ./.git/hooks/commit-msg
备注:这两个命令不敲就没有change-id
$ echo "* -text"> .git/info/attributes #为了解决 dos环境下跟 unix的转换问题 - 回车和回车换行,windows和linux的区别。
3.
3.1 检出远端仓库
git clone ssh://[email protected]:29418/scm_il/SS_ILFT
3.2 显示分支
git branch –a显示所有分支 git branch –help输出所有参数
3.3 添加文件
git add <filename> 把这些文件添加到缓存区
3.4 提交文件
git commit –m “代码提交信息”
通过这步,你的改动已经提交到了HEAD,但是还没到远端仓库
先提交一下才能生成Change-Id,用git log -1查看一下
modify commit: git commit –amend
commit的备注信息有一定的格式,需要从http://eclipseupd.china.nsn-net.net/svnlogtemp/获取
3.5 推送改动
git push origin HEAD:refs/for/分支信息
原因是gerrit不允许直接将本地修改同步到远程仓库。客户必须先push到远程仓库的refs/for/*分支上,等待审核。gerrit本身就是个代码审核工具。