- 切换分支
git checkout name
- 撤销修改
git checkout -- file
- 删除文件
git rm file
- 查看状态
git status
- 添加记录
git add file
或
git add .
- 添加描述
git commit -m "miao shu nei rong"
- 同步数据
git pull
- 提交数据
git push origin name
分支操作
- 查看分支
git branch
- 创建分支
git branch name
- 切换分支
git checkout name
- 创建+切换分支
git checkout -b name
- 合并某分支到当前分支
git merge name
- 删除分支
git branch -d name
- 删除远程分支
git push origin :name
- 拉取远程分支到本地
git checkout -b <branch> <remote>/<branch>
或者
git checkout --track <remote>/<branch>
- 撤销提交(未push的情况下)
git reset --mixed <SHA1>
# 此SHA1之后的commit全部撤消,并回退index,工作空间代码不变,--mixed可省略
git reset --soft <SHA1>
# 此SHA1之后的commit全部撤消,工作空间代码和index不变
git reset --hard <SHA1>
# 此SHA1之后的commit全部撤消,工作空间代码和index全部退回
- 查看commit的记录,
git log --oneline -n
#单行显示最后n个commit的记录
- 本地分支和远程分支做关联
git branch --set-upstream-to=<remote>/<remote_branch> <loclal_branch>