重温git命令发现他还有如此奥妙之处,值得继续探索
(本文适合了解部分git命令的读者,预计阅读5分钟,若跟着体验则需要1小时左右)
1、git init 初始化仓库(新建一个git仓库)
![](https://img.haomeiwen.com/i6952478/59e3b1d0e8c8d88f.png)
![](https://img.haomeiwen.com/i6952478/4ebb468d1cdcbc48.png)
2、git clone 从远程服务器克隆代码到本地(后面加项目名可以重命名)
![](https://img.haomeiwen.com/i6952478/ce5b78519c90d4c3.png)
3、git status 查看仓库此时的状态(每次开始修改项目前都先看一下此时的状态)
![](https://img.haomeiwen.com/i6952478/ff7f054001802f5e.png)
4、git log 查看仓库所有提交日志(可以查看项目所有的commit默认记录 --oneline只显示单行记录、--stat显示详细记录包括修改的文件、 -p显示补丁信息即修改具体的代码块)
![](https://img.haomeiwen.com/i6952478/89ee7e6bee707d4a.png)
![](https://img.haomeiwen.com/i6952478/cc1682a1b9d86c70.png)
![](https://img.haomeiwen.com/i6952478/e5224560501493e3.png)
![](https://img.haomeiwen.com/i6952478/2c2cdfcf595e420d.png)
tips:冒号代表git分页功能,可使用上图进行查看操作
5、git show 显示一个特定commitID的详细记录
![](https://img.haomeiwen.com/i6952478/cb93cc9fa42cac66.png)
6、git add 把修改文件添加至暂存区
![](https://img.haomeiwen.com/i6952478/163c6f47e648d518.png)
![](https://img.haomeiwen.com/i6952478/86ebc4f75ccae35b.png)
7、git commit 把暂存区的修改文件提交到本地仓库(-m “提交说明” --amend更改最后一个commit)
![](https://img.haomeiwen.com/i6952478/29a174ae35ecfd33.png)
![](https://img.haomeiwen.com/i6952478/3d6489b64fbcb8ce.png)
![](https://img.haomeiwen.com/i6952478/b7e252f94030ff2b.png)
8、git diff 查看尚未commit提交的修改
![](https://img.haomeiwen.com/i6952478/dcccaeb2bfac2e84.png)
9、.gitignore 文件用来记录忽略提交的文件
![](https://img.haomeiwen.com/i6952478/e3aa9db8a2196260.png)
10、git tag 添加(-d 删除)标签
![](https://img.haomeiwen.com/i6952478/fc53f3f439106c25.png)
![](https://img.haomeiwen.com/i6952478/97cf2cef5481d9a8.png)
11、git branch 创建(-d 删除)分支
![](https://img.haomeiwen.com/i6952478/21d5ffd07426bde2.png)
![](https://img.haomeiwen.com/i6952478/ddf538de80608a8d.png)
12、git checkout (-b 创建并)切换到某个分支
![](https://img.haomeiwen.com/i6952478/f7b116d7cc7b6a8d.png)
![](https://img.haomeiwen.com/i6952478/1aa6a7715371966e.png)
13、git merge 合并特定分支到当前分支(有两种类型)
![](https://img.haomeiwen.com/i6952478/eb23e3ffd0133acc.png)
14、git revert 还原commit
![](https://img.haomeiwen.com/i6952478/bef12284a1730dcd.png)
15、git reset 重置commit
![](https://img.haomeiwen.com/i6952478/bbb9a4492e32eaeb.png)
16、其他
![](https://img.haomeiwen.com/i6952478/867f2d35d47639dd.png)
![](https://img.haomeiwen.com/i6952478/7fb4aeefaff08c95.png)
![](https://img.haomeiwen.com/i6952478/d1b0efbd49ccaac9.png)
![](https://img.haomeiwen.com/i6952478/4ea2915faecca2eb.png)
(注:上图设置sublime text 路径前少了一个单引号,复制自行加上)
网友评论