git是版本控制的工具
工作区 当前工作的地方
缓存区 git add 之后存到的地方就叫缓存区
版本库 git commit 之后存到的地方就叫版本库
初始设置
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git init 初始化
git status 查看状态
git add 添加到缓存区
git add . 添加全部到缓存区
git commit 提交到版本库
git log 查看提交记录,当前位置往前的提交记录
git reflog 查看所有的提交记录
git reset HEAD 从缓存区把文件拉取到工作区
git reset --hard 回滚到某一个版本,可以写log的长的值,也可以写reflog的短的值
git diff 对比的是工作区跟缓存区之间的差别
git diff --cached 对比缓存区跟版本库之间的差别
git checkout -- filename 取消修改的内容
git log --pretty=oneline 只显示一行 md5 和 提交名
git log --pretty=format
选项 | 说明 |
%H |
提交对象(commit)的完整哈希字串 |
%h |
提交对象的简短哈希字串 |
%T |
树对象(tree)的完整哈希字串 |
%t |
树对象的简短哈希字串 |
%P |
父对象(parent)的完整哈希字串 |
%p |
父对象的简短哈希字串 |
%an |
作者(author)的名字 |
%ae |
作者的电子邮件地址 |
%ad |
作者修订日期(可以用 --date= 选项定制格式) |
%ar |
作者修订日期,按多久以前的方式显示 |
%cn |
提交者(committer)的名字 |
%ce |
提交者的电子邮件地址 |
%cd |
提交日期 |
%cr |
提交日期,按多久以前的方式显示 |
%s |
提交说明 |
分支
git branch name 新建分支
git branch 查看分支
git branch -d name 删除分支
git checkout name 切换到某个分支
git checkout -b name 创建分支并切换分支
git merge name 同步(合并)分支
stash
git stash 将当前开发的内容放在某个地方
git stash pop 恢复当前的工作目录,并删除
git stash list 查看stash列表
git stash drop 删除stash
git stash apply 恢复当前的工作目录,不删除stash
github
git push origin dev 将本地版本库的内容上传到远程仓库
git clone https://github.com/Ning-qianLiu/aoin.git 将远程仓库的代码拉取到本地
git pull 拉取远程仓库的代码到本地
git remote add origin https://github.com/Ning-qianLiu/aoin.git #给远程仓库创建一个别名
git fetch # 拉取远程仓库的代码到本地的代码库
git merge origin/dev #同步fetch的版本后, 版本库还没有, 需要merge一下
git tag # 列出标签
git tag -a v1.4 -m 'my version 1.4' #附注标签
git push origin --tags #提交标签
git tag -d v1.4-lw #删除标签