Git 教程之查看提交历史详解

所属分类: 网络编程 / 相关技巧 阅读数: 1349
收藏 0 赞 0 分享

Git 查看提交历史

在使用 Git 提交了若干更新之后,又或者克隆了某个项目,想回顾下提交历史,我们可以使用 git log 命令查看。
针对我们前一章节的操作,使用 git log 命令列出历史提交记录如下:

$ git log
commit 88afe0e02adcdfea6844bb627de97da21eb10af1
Merge: 14b4dca d7e7346
Author: w3cschool <w3c@w3cschool.cc>
Date:  Sun Mar 1 15:03:42 2015 +0800

  Merge branch 'change_site'
  
  Conflicts:
    test.txt

commit 14b4dcadbdc847207651d5a9fae0d315057f346e
Author: w3cschool <w3c@w3cschool.cc>
Date:  Sun Mar 1 14:53:15 2015 +0800

  新增加一行

commit d7e734640da06055e107eaf29cf350b3f1de1c2c
Author: w3cschool <w3c@w3cschool.cc>
Date:  Sun Mar 1 14:48:57 2015 +0800

  changed the site

commit 556f0a0637978097b82287ac665a717623b21f3f
Author: w3cschool <w3c@w3cschool.cc>
Date:  Sun Mar 1 14:40:34 2015 +0800

  removed test2.txt

我们可以用 --oneline 选项来查看历史记录的简洁的版本。

$ git log --oneline
88afe0e Merge branch 'change_site'
14b4dca 新增加一行
d7e7346 changed the site
556f0a0 removed test2.txt
2e082b7 add test2.txt
048598f add test.txt
85fc7e7 test comment from w3cschool.cc

这告诉我们的是,此项目的开发历史。

我们还可以用 --graph 选项,查看历史中什么时候出现了分支、合并。以下为相同的命令,开启了拓扑图选项:

$ git log --oneline --graph
*  88afe0e Merge branch 'change_site'
|\ 
| * d7e7346 changed the site
* | 14b4dca 新增加一行
|/ 
* 556f0a0 removed test2.txt
* 2e082b7 add test2.txt
* 048598f add test.txt
* 85fc7e7 test comment from w3cschool.cc

现在我们可以更清楚明了地看到何时工作分叉、又何时归并。

你也可以用 '--reverse'参数来逆向显示所有日志。

$ git log --reverse --oneline
85fc7e7 test comment from w3cschool.cc
048598f add test.txt
2e082b7 add test2.txt
556f0a0 removed test2.txt
d7e7346 changed the site
14b4dca 新增加一行
88afe0e Merge branch 'change_site'

如果只想查找指定用户的提交日志可以使用命令:git log --author , 例如,比方说我们要找 Git 源码中 Linus 提交的部分:

$ git log --author=Linus --oneline -5
81b50f3 Move 'builtin-*' into a 'builtin/' subdirectory
3bb7256 make "index-pack" a built-in
377d027 make "git pack-redundant" a built-in
b532581 make "git unpack-file" a built-in
112dd51 make "mktag" a built-in

如果你要指定日期,可以执行几个选项:--since 和 --before,但是你也可以用 --until 和 --after。

例如,如果我要看 Git 项目中三周前且在四月十八日之后的所有提交,我可以执行这个(我还用了 --no-merges 选项以隐藏合并提交):

$ git log --oneline --before={3.weeks.ago} --after={2010-04-18} --no-merges
5469e2d Git 1.7.1-rc2
d43427d Documentation/remote-helpers: Fix typos and improve language
272a36b Fixup: Second argument may be any arbitrary string
b6c8d2d Documentation/remote-helpers: Add invocation section
5ce4f4e Documentation/urls: Rewrite to accomodate transport::address
00b84e9 Documentation/remote-helpers: Rewrite description
03aa87e Documentation: Describe other situations where -z affects git diff
77bc694 rebase-interactive: silence warning when no commits rewritten
636db2c t3301: add tests to use --format="%N"

更多 git log 命令可查看:http://git-scm.com/docs/git-log

更多精彩内容其他人还在看

firefox 扩展开发技巧

firefox 扩展开发
收藏 0 赞 0 分享

php asp.net 比较 [推荐]

如今当提到 Web 开发时,您有许多选择。这些方法中许多都涉及到预处理 - 即,利用特定的标记将代码嵌入到 HTML 页面中
收藏 0 赞 0 分享

UTF-8 BOM 可能导致样式错乱的解决方法

utf-8 是一种在web应用中经常使用的一种 unicode 字符的编码方式,使用 utf-8 的好处在于它是一种变长的编码方式,对于 ANSII 码编码长度为1个字节,这样的话在传输大量 ASCII 字符集的网页时,可以大量节约网络带宽。
收藏 0 赞 0 分享

Web 开发常用工具 大家自己查找下载

看到了Web通信分析工具 这篇文章,除了burpsuite其他我日常都经常使用。于似乎我整理了一下我自己用的其他的WEB开发工具。
收藏 0 赞 0 分享

遇到不能复制的网站怎么办?

有时我们看到喜欢的网页内容时定会产生复制下来为我所用的冲动,不过当你点击鼠标时它却没有任何反应,选择的内容没有任何变化,不禁有点扫兴。不要紧,办法总比困难多!
收藏 0 赞 0 分享

URL 长度有限制吗?

众所周知, 传递小量参数(在没有其他原因,例如隐藏参数值的情况下)推荐使用GET方法,传递大量参数推荐使用POST方法。原因是什么呢?
收藏 0 赞 0 分享

声音验证码制作方法

收听验证码已经比较普遍了,使用户看不清楚的情况下可以通过耳朵来收听验证码,但网上搜了很久没看到有具体的制作方法,自己想了想,还是按自己的方法来实现了,呵呵。
收藏 0 赞 0 分享

防范SQL注入式攻击

SQL注入式攻击是利用是指利用设计上的漏洞,在目标服务器上运行Sql命令以及进行其他方式的攻击动态生成Sql命令时没有对用户输入的数据进行验证是Sql注入攻击得逞的主要原因。
收藏 0 赞 0 分享

Web 设计与开发者必须知道的 15 个站点

今天读到一篇文章,介绍了15个对 Web 设计与开发师极端有用的站点,里面有不少也是我们一直在使用的,也许对很多人都有用,翻译出来以饷同仁。
收藏 0 赞 0 分享

十分钟内学会 避免用户刷新导致重复POST提交

在Web应用中,采用POST提交信息是非常常见的,然而如果目标页面打开得太慢,用户就可能会刷新页面,这时候之前已经提交过的信息就会被重复提交。
收藏 0 赞 0 分享
查看更多