@rickyChen
2018-05-09T06:36:33.000000Z
字数 1791
阅读 2096
Git
安装
yum install git//建议安装版本>1.8
简易的命令行入门教程
Git全局设置:
git config --global user.name "RickyHuo"git config --global user.email "huochen1994@163.com"//配置git当前用户信息
创建git仓库:
mkdir testcd testgit init//将当前目录初始化touch README.mdgit add README.md//把README.md添加到git管理git commit -a -m "first commit"//将修改保存到本地库中,双引号内为本次提交注释内容git remote add origin https://github.com/apache/spark.git//在git服务器新建一个源于当前目录连接git push -u origin master//将最新的修改同步到git服务器端的master分支
已有项目?
git clone https://github.com/apache/spark.gittouch README.md//从远端下载文件git commit -a -m "update ..."git push -u origin master
理解并使用分支
使用分支可以让你从开发主线上分离开来,然后在新的分支上解决特定问题,同时不会影响主线
git branch (-a)//显示当前所在分支(显示该项目所有分支)git branch testing//创建一个名为testing的分支git checkout (-b) testing//切换到testing分支(创建并切换到testing分支)git branch -d testing//删除testing分支,仅删除本地,不删除远端分支git branch -m oldbranch newbranch//重命名分支git merge (--no-ff) branch1//将branch1分支合并到当前分支//--no-ff:保留分支的commit历史git push origin --delete branch1git push origin :branch1//删除远端的分支
版本回退
git checkout -f filename//撤销该文件在工作区的修改git reset HEAD filename//撤销该文件在暂存区的修改git reset --hard xxx//版本回退,回退到commit点为xxx的版本
其他命令
git status//可以列出当前目录所有还没有被git管理的文件和被git管理且被修改但还未提交(git commit)的文件.git diff//列出当前目录于最新的commit点的不同git diff a b//列出变量a和b的不同,其中变量可为commit信息、版本信息等git log//列出之前所有commit记录git reflog//列出所有commit历史记录git commit --amend --reset-author
快捷键设置
vim ~/.bashrc#git aliasalias gl='git log --graph --oneline --decorate'alias gl2='git log --pretty=format:"%h%x09%an%x09%ad%x09%s" --graph'alias gbr='git branch'alias gcb='git checkout'alias gnb='git checkout -b'alias gcm='git commit -a'alias gsta='git status -s'source ~/.bashrc
颜色设置
git config --global color.status autogit config --global color.diff autogit config --global color.branch autogit config --global color.interactive auto
references
git - 简易指南
http://www.bootcss.com/p/git-guide/
Git -Documentation
http://git-scm.com/doc
github - Hello World
https://guides.github.com/activities/hello-world/