Git 开发基本流程与命令
从服务器克隆项目(178/gerrit)
git clone root@192.168.2.178:/root/git_repository/xxx.git
git clone ssh://account@192.168.2.178:29418/xxx.git
合并服务器的代码提交
git fetch origin branch_name
git rebase origin/branch_name //推荐
提交本地代码到服务器 (178)
git push origin branch_name 提交本地代码到服务器 (gerrit 代码审核服务器)
git push origin branch_name:refs/for/branch_name
在现有本地仓库中添加远程仓库(178/gerrit)
git remote add remote_name ssh://account@192.168.2.178:29418/xxx.git
git remote add remote_name root@192.168.2.178:/root/git_repository/xxx.git
|
本地仓库常用操作
git branch -av //查看分支情况,a:全部分支,包括远程分支,v:显示分支最后一次提交信息 git branch branch_name //创建新的分支,一般开发新功能可创建分支feature-xxx,完成后在develop上rebase feature-xxx以实现合并 git add . //将变更添加到暂存区域 git commit -am 'commit message' //提交所有变更到本地仓库 git checkout branch_name //切换到指定分支 git merge branch_name //合并分支到当前分支 git rebase branch_name //rebase 分支 |
gerrit SSH Key 配置
打开终端,进入目录
cd ~/.ssh 备份或移除现有ssh key
$ ls
# Lists all the subdirectories in the current directory
# config id_rsa id_rsa.pub known_hosts
$ mkdir key_backup
# Makes a subdirectory called "key_backup" in the current directory
$ cp id_rsa* key_backup
# Copies the id_rsa keypair into key_backup
$ rm id_rsa*
# Deletes the id_rsa keypair
创建新的ssh key
$ ssh-keygen -t rsa -C "your_email@youremail.com" # Creates a new ssh key using the provided email # Generating public/private rsa key pair. # Enter file in which to save the key (/home/you/.ssh/id_rsa): # Enter passphrase (empty for no passphrase): [Type a passphrase] # Enter same passphrase again: [Type passphrase again] # Your identification has been saved in /home/you/.ssh/id_rsa. # Your public key has been saved in /home/you/.ssh/id_rsa.pub. # The key fingerprint is: # 01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db your_email@youremail.com 全部完成后打开id_rsa.pub
vim .ssh/id_rsa.pub 拷贝全部内容,包含邮件地址到Gerrit |
奔跑...