1.前提
- Remote 远程仓库
- Repository 本地仓库
- Index/Stage 暂存区
- Workspace 工作区
2.常用的指令
[]:参数
- git init [project-name] 新建git代码库
- git clone [url] 下载一个项目和整个代码历史
- git config –list 显示当前git配置
- git config –global user.name = “[name]” 设置全局的用户账号 将name换成password即为密码
- git add . 将当前目录下添加到暂存区
- git commit -m “[message]” 提交暂存区的文件到本地仓库
- git commit -v 提交时显示所有的diff信息
- git branch 列出所有本地分支 -r 远程分支 -a所有分支
- git checkout -b [branch] 新建一个分支并切换到这个分支
- git branch -d [branch] 删除本地分支
- git push origin –delete [branch] 删除远程仓库分支
- git tag 列出所有tag
- git tag [tag] 新建一个tag在当前commit
- git push origin [tag] 提交指定的tag
- git status 显示有变更的文件
- git log 查看当前分支的历史版本
- git diff 显示暂存区与工作区的差异
- git fetch origin 下载远程仓库的所有变动
- git remote -v 显示所有远程仓库
- git pull origin [branch] 拉取远程仓库的变化与本地当前分支合并
- git push origin [branch] 上传本地指定分支到远程仓库
- git checkout 恢复暂存区的所有文件到工作区
- git stash 暂时将未提交的变化移除
参考地址为http://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.html