- workspace:工作区
Index/stage:暂存区
- Repository:仓库区/本地仓库
- Remote:远程仓库
引用地址:http://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.html
新建代码库:
-
git init:在现有目录中初始化仓库
-
git clone:克隆现有的仓库
增加/删除文件
-
git add:暂存已修改文件
-
git add . :会递归地添加当前工作目录中的所有文件
-
git rm
[file1] [file2] ...
:删除工作区文件,并且将这次删除放入暂存区
代码提交:
-
git commit:提交已经被add进来的改动, git commit -m “the commit message"
-
git commit -a :提交工作区自上次commit之后的变化,直接到仓库区
-
gitcommit -v :提交时显示所有diff信息
标签:
-
git push [remote] [tag] :
提交指定tag
-
git push [remote] --tags: 提交所有tag
查看信息:
-
git log:显示当前分支的版本历史
- git status : 显示所有变更的文件
-
git diff :显示暂存区和工作区的差异
-
git diff --cached [file] :
显示暂存区和上一个commit的差异
-
git diff HEAD :
显示工作区与当前分支最新commit之间的差异
远程同步:
-
git fetch [remote] :
下载远程仓库的所有变动
-
git pull [remote] [branch] :
取回远程仓库的变化,并与本地分支合并
-
git push [remote] [branch]:
上传本地指定分支到远程仓库
-
git push [remote] --all :
推送所有分支到远程仓库
撤销:
-
git checkout [file] :
恢复暂存区的指定文件到工作区
-
git checkout [commit] [file]:
恢复某个commit的指定文件到暂存区和工作区
-
git chekout . :
恢复暂存区的所有文件到工作区