简单了解git命令
linux下
打开终端 locate .gitconfig找到gitconfig文件的位置, vim .gitconfig然后添加如下: [user] name = 雷腾 email = lvjavapro@163.com [core] editor = vim excludesfile = /root/.gitignore [alias] st = status ci = commit df = fiff co = checkout br = branch lol = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ "~/.gitconfig" 13L, 307C 在alias下添加命令的缩写然后就可以尽情的提升你的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 settings -> SSH Public Keys 输入后点添加
后面附录天天在项目中基本都要用到的git提交代码的命令
git st git br -av --color git add . git st git ci -am "提交的注释的信息" git br -av git remote update 输入密码 git br -av 如果显示ahead几个版本而且落后几个版本就需要整合. git fetch origin you_brancName 输入密码 然后整合origin和你的分支 git rebase origin/your_branch git push origin your_branch 输入密码 git br -av git st
所有评论(0)