1. 安装后的初始化:
git config --global user.name "your name"
git config --global user.email "your email"
git config --global credential.helper store # 记录账户密码,免去每次都输入
2. 常规操作
git init #初始化一 git 仓库
git add "filename" # 添加文件
git rm --cached file # 从未提交的缓冲区删除文件(未受管理状态)
git rm file # 从版本库中删除
git commit -m "本次提交的描述信息" #提交到本地仓库
git log # 查看历史记录(只包含提交)
git reflog # 查看操作日志(历史命令)
git status # 查看状态
git diff # 查看不同
3. 回退
git reset --hard HEAD^ # 上一个版本号
git reset --hard 指定的版本号 # 恢复到指定版本号
4. 撤销修改(就是会退到上一次 git commit 或 git add 时的状态)
git checkout -- filename
撤销修改包含撤销删除的文件
5. 远程仓库
# 关联一个远程仓库
git remote add origin https://github.com/***.git;
# 推送至远程仓库的 master 分支
git push -u origin master
# 从远程仓库克隆
git clone https://github.com/***.git
6. 分支
git branch dev # 创建分支
git checkout dev # 切换分支
git checkout -b dev2 # 创建并切换
git branch # 查看分支状态
git merge dev # 和 dev 分支合并
git branch -d dev # 删除 dev 分支
7. 标签
git tag v1.0 # 给当前分支当前状态打标签
git tag v0.9 f52c633 # 对特定的一次提交打标签
git tag # 查看所有标签
git show v0.9 # 查看标签信息
# -a 标签名 -m 标签信息
git tag -a v0.1 -m "version 0.1 released" 1094abd