Git笔记

May 6, 2018


Git Log

查看Git的提交历史命令

普通

huanhuang@localhost:~/Study/HuangHuanBlog$ git log
commit 964268b3493e9245f94ca72029cea417a6898751 (HEAD -> gh-pages, origin/gh-pages, origin/HEAD)
Author: huanghuan02 <huanghuan02@meituan.com>
Date:   Thu May 3 20:15:23 2018 +0800

    修改错误拼写

commit 61660c4f8595d0c10abe77f56c77bb1c5f8c6d3d
Author: huanghuan02 <huanghuan02@meituan.com>
Date:   Wed May 2 09:28:13 2018 +0800

    更新图片

commit c98048b57e90c83fe0ed802d8cb4f1251a30076e
Author: huanghuan02 <huanghuan02@meituan.com>
Date:   Tue May 1 18:10:43 2018 +0800

    MySQL MVCC

显示差异

huanhuang@localhost:~/Study/HuangHuanBlog$ git log -p
commit 964268b3493e9245f94ca72029cea417a6898751 (HEAD -> gh-pages, origin/gh-pages, origin/HEAD)
Author: huanghuan02 <huanghuan02@meituan.com>
Date:   Thu May 3 20:15:23 2018 +0800

    修改错误拼写

diff --git a/_posts/2018-05-01-MVCC.md b/_posts/2018-05-01-MVCC.md
index f74ba2a..ea4000a 100644
--- a/_posts/2018-05-01-MVCC.md
+++ b/_posts/2018-05-01-MVCC.md
@@ -80,7 +80,7 @@ MySQL的Innodb引擎支持多种事务隔离级别,而其中的RR级别(Repe

 ![Transaction visibility](/HuangHuanBlog/pics/transaction_visibility.png)

-通过上图(这个图是通过分析网上的一些博客内容得到的,和实际MySQL的逻辑细节可能不一致),在来分析上文提到的Case,由于事务B的事务ID不满足`read_id=tid||tid<min_tid`的条件,且该记录当前有`DATA_ROLL_PTP`,所以最后该事务B实际读取的是Undo Log中的记录:
+通过上图(这个图是通过分析网上的一些博客内容得到的,和实际MySQL的逻辑细节可能不一致),在来分析上文提到的Case,由于事务B的事务ID不满足`read_id=tid||tid<min_tid`的条件,且该记录当前有`DATA_ROLL_PTR`,所以最后该事务B实际读取的是Undo Log中的记录:

 | Primary Key | Time      | Name | DATA_TRX_ID | DATA_ROLL_PTR |
 | ----------- | --------- | ---- | ----------- | ------------- |

commit 61660c4f8595d0c10abe77f56c77bb1c5f8c6d3d
Author: huanghuan02 <huanghuan02@meituan.com>
Date:   Wed May 2 09:28:13 2018 +0800

    更新图片

极简显示

huanhuang@localhost:~/Study/HuangHuanBlog$ git log --pretty=oneline
964268b3493e9245f94ca72029cea417a6898751 (HEAD -> gh-pages, origin/gh-pages, origin/HEAD) 
修改错误拼写
61660c4f8595d0c10abe77f56c77bb1c5f8c6d3d 更新图片
c98048b57e90c83fe0ed802d8cb4f1251a30076e MySQL MVCC
c39e07b51c14b6e966c1798be6cdf1531e36d925 内容优化
50eff98bc148a0fa76b8fdc06ce6a280f2f92e13 MySQL 5.7 死锁原因
22b08846d46eff65fd29c8482e4457267cefc287 whatever
821d18625f1653b612a4015f1bb97d67033ddedf 2018回归!
252854d2c2f2774ffa019c2e34130ae514b2b438 MOD:调整格式
d3e0962a1311a3edf723878e137929ecdd674c85 MOD:增加了第二周分析,完成了这篇博客
d3df279b4a82b74c4f49fade15a0ace4f18ffe79 ADD:第一周会计表
226fff7935518c1fc47b61b930a553cc8e4b1fd2 ADD:利润表
1f5f32ec1cd02ea4d266b5cb5f63753dee6e6637 ADD:会计小结
af3d7c86242238edd1a7e70410d15962f445b58f ADD:死锁章完成
2ecc010e50d5e28a40f8cb886c82811660e3008c ADD: Innodb范例
5a615870c3b795df2d73432b029a712633324eec ADD: Innodb死锁
bbad334d8249181f6254cc800e9fc0698c7538bb ADD: Innodb死锁
53f0015ee07a492847ad8d019ddbe154fe06d372 ADD: php自动化测试
f5f05d5aeb9f5d2baff09f13ce69233dc58cec6c MOD: 更新文档
f8f2acc032eefc2004dca42cd40ffd2af1344694 ADD: Innodb锁介绍
cae98b5c5d39e43b78489dd5ccfc48813f8d5d2c ADD: Innodb锁详细介绍
e3d233612b8b71326fa15d24765cd32392995cd8 ADD: maven docs

其它

#图形显示,也就是有个时间轴
git log --graph

Git Tag

Tag是打标签,可用来作为发布版本管理

#显示已有标签
git tag

#打标签
git tag -a tagName -m comment
git tag -a 0.5.5 -m '发布版 0.5.5'

#显示tag信息
git show 0.5.5

#推到服务器
git push origin 0.5.5

#本地删除和远程删除
git tag -d 0.5.5
git push origin :refs/tags/0.5.5

Git Reset

重置

#本地回滚到指定commit
git reset <commit>

#本地reset后远程同步
git push -f origin master

Git Grep

代码搜索

####搜索包含指定字符的文件

huanhuang@localhost:~/Study/HuangHuanBlog$ git grep '2018'
_posts/2018-04-15-MySQL5.7问题.md:date:   2018-04-15 23:15 +0800
_posts/2018-05-01-MVCC.md:date:   2018-05-01 14:26 +0800
_posts/2018-05-01-MVCC.md:| 1           | 2018-4-28 | Huan | 1           | NULL          |
_posts/2018-05-01-MVCC.md:| 1           | 2018-4-28 | Huan | 1           | NULL          |
_posts/2018-05-06-Git.md:date:   2018-05-06 21:05:00 +0800
_posts/2018-05-06-Git.md:Date:   Thu May 3 20:15:23 2018 +0800
_posts/2018-05-06-Git.md:Date:   Wed May 2 09:28:13 2018 +0800
_posts/2018-05-06-Git.md:Date:   Tue May 1 18:10:43 2018 +0800
_posts/2018-05-06-Git.md:Date:   Thu May 3 20:15:23 2018 +0800

显示行号

huanhuang@localhost:~/Study/HuangHuanBlog$ git grep -n '2018'
_posts/2018-04-15-MySQL5.7问题.md:4:date:   2018-04-15 23:15 +0800
_posts/2018-05-01-MVCC.md:4:date:   2018-05-01 14:26 +0800
_posts/2018-05-01-MVCC.md:66:| 1           | 2018-4-28 | Huan | 1           | NULL          |
_posts/2018-05-01-MVCC.md:87:| 1           | 2018-4-28 | Huan | 1           | NULL          |
_posts/2018-05-06-Git.md:4:date:   2018-05-06 21:05:00 +0800
_posts/2018-05-06-Git.md:19:Date:   Thu May 3 20:15:23 2018 +0800
_posts/2018-05-06-Git.md:25:Date:   Wed May 2 09:28:13 2018 +0800
_posts/2018-05-06-Git.md:31:Date:   Tue May 1 18:10:43 2018 +0800

只显示文件名

huanhuang@localhost:~/Study/HuangHuanBlog$ git grep --name-only '2018'
_posts/2018-04-15-MySQL5.7问题.md
_posts/2018-05-01-MVCC.md
_posts/2018-05-06-Git.md
_posts/2018-05-13-乐观锁和悲观锁.md
_site/develop/2018/05/06/Git.html
_site/feed.xml
_site/index.html
_site/mysql/2018/04/15/MySQL5.7问题.html
_site/mysql/2018/05/01/MVCC.html
_site/mysql/2018/05/13/乐观锁和悲观锁.html
_site/page2/index.html
_site/page3/index.html
_site/page4/index.html
_site/read/2017/06/19/会计学入门小结.html

显示每个文件中匹配的个数

huanhuang@localhost:~/Study/HuangHuanBlog$ git grep -c '2018'
_posts/2018-04-15-MySQL5.7问题.md:1
_posts/2018-05-01-MVCC.md:3
_posts/2018-05-06-Git.md:38
_posts/2018-05-13-乐观锁和悲观锁.md:1
_site/develop/2018/05/06/Git.html:13
_site/feed.xml:25
_site/index.html:16
_site/mysql/2018/04/15/MySQL5.7问题.html:3
_site/mysql/2018/05/01/MVCC.html:6
_site/mysql/2018/05/13/乐观锁和悲观锁.html:3
_site/page2/index.html:8
_site/page3/index.html:8
_site/page4/index.html:8
_site/read/2017/06/19/会计学入门小结.html:1

上一篇博客:MySQL MVCC介绍
下一篇博客:乐观锁&悲观锁