Git 常用命令清单
2016-08-19 本文已影响13人
煒weelion
![](https://img.haomeiwen.com/i1331329/2582caa933f91a88.jpg)
用户设置
git config global user.name <username>
git config global user.email <email>
初始化版本库
git init
添加远程版本库
git remote add <name> <repo-url>
克隆版本库
git clone <repo-url>
添加文件到版本库跟踪列表
git add <filename>
查看本次修改的跟踪文件
git status
在版本库跟踪列表删除文件
git reset <filename>
使用场景:此次提交包含了不相干文件
撤销文件改动
git checkout <filename>
使用场景:撤销本地文件修改
提交改动到本地版本库
git commit
提交历史查看
git log
提交回退(硬)
git reset --hard <commit-hash>
注意: 此命令在 <commit-hash> 之后提交的版本都会消失
提交回退(软)
git reset --soft <commit-hash>
不同于 hard 在 <commit-hash> 之后提交的版本都会留在跟踪列表
将本地版本库的版本提交到远程版本库
git push <remote> <branch-name>
最后给大家一张 git 操作流
![](https://img.haomeiwen.com/i1331329/a993350bb01f754b.jpg)