1 安装
# centos 上安装git
yum install git
# ubuntu 、 deepin 安装git
sudo apt-get install git
2 配置
2.1 个人信息
# 设置邮件地址
git config --global user.email <"email">
# 设置用户名
git config --global user.name <"username">
2.2 配置alias
为什么有些人命令行敲的飞快?git alias了解一下~
git config --global alias.a add
git config --global alias.br branch
git config --global alias.ck checkout
git config --global alias.cm commit -m
git config --global alias.cp cherry-pick
git config --global alias.mg merge
git config --global alias.fo fetch origin
git config --global alias.po push origin
git config --global alias.re rebase
git config --global alias.s status
git config --global alias.sh stash
git config --global alias.sp stash pop
我只需要git s、git a、git cm "feature 111"、 git fo、 git re、 git po,就能完成一次提交。
其实还是以更简单,alias git = g
3 版本库操作
3.1 初始化版本库
创建仓库
git init
添加文件
在版本库中更新文件 git add <file>
删除文件
git rm git commit
提交变更
git commit -m "提交信息"
commit id --SHA1
查看版本库信息
git status
查看文件变更
git diff <file>
4 分支管理
分支就是一条记录版本库每一次提交的时间线,其中主分支成为master, 由head指针跟踪指向
创建分支
git branch <branch>
切换分支
git checkout <branch>
创建并切换分支
git checkout -b <branch>
查看分支
git branch
合并到主分支
git merge <branch>
删除合并后的分支
git branch -d <branch>
临时管理分支
备份工作区环境
git stash
查看备份工作区
git stash list
还原并清理工作目录
git stash pop