下载一个项目和它的整个代码历史
$ git clone [url]
添加指定文件到暂存区
$ git add [file1] [file2] …
添加当前目录的所有文件到暂存区
$ git add .
添加每个变化前,都会要求确认
对于同一个文件的多处变化,可以实现分次提交
$ git add -p
选择一个commit,合并进当前分支
$ git cherry-pick [commit]
提交暂存区到仓库区
$ git commit -m [message]
提交暂存区的指定文件到仓库区
$ git commit [file1] [file2] … -m [message]
列出所有本地分支
$ git branch
列出所有本地分支和远程分支
$ git branch -a
新建一个分支,但依然停留在当前分支
$ git branch [branch-name]
切换到上一个分支
$ git checkout -
删除分支
$ git branch -d [branch-name]
显示有变更的文件
$ git status
显示当前分支的版本历史
$ git log
显示暂存区和工作区的代码差异
$ git diff
显示某次提交的元数据和内容变化
$ git show [commit]
从本地master拉取代码更新当前分支:branch 一般为master
$ git rebase [branch]
git remote update --更新远程仓储
取回远程仓库的变化,并与本地分支合并
$ git pull [remote] [branch]
上传本地指定分支到远程仓库
$ git push [remote] [branch]
重置暂存区与工作区,与上一次commit保持一致
$ git reset --hard