05 Git 基础 – 查看提交历史
2026/4/27 22:03:07 网站建设 项目流程

查看提交历史

在提交了若干更新,又或者克隆了某个项目之后,你也许想回顾下提交历史。 完成这个任务最简单而又有效的工具是 git log 命令。

接下来的例子会用我专门用于演示的 simplegit 项目, 运行下面的命令获取该项目源代码:

git clone https://github.com/schacon/simplegit-progit

然后在此项目中运行 git log,应该会看到下面的输出:

$ git log commit ca82a6dff817ec66f44342007202690a93763949Author:ScottChacon<schacon@gee-mail.com>Date:MonMar1721:52:112008-0700changed the version number commit085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7Author:ScottChacon<schacon@gee-mail.com>Date:SatMar1516:40:332008-0700removed unnecessary test commit a11bef06a3f659402fe7563abf99ad00de2209e6Author:ScottChacon<schacon@gee-mail.com>Date:SatMar1510:31:282008-0700first commit

默认不用任何参数的话,git log 会按提交时间列出所有的更新,最近的更新排在最上面。 正如你所看到的,这个命令会列出每个提交的 SHA-1 校验和、作者的名字和电子邮件地址、提交时间以及提交说明。

git log 有许多选项可以帮助你搜寻你所要找的提交, 接下来我们介绍些最常用的。

一个常用的选项是 -p,用来显示每次提交的内容差异。 你也可以加上 -2 来仅显示最近两次提交:

$ git log-p-2commit ca82a6dff817ec66f44342007202690a93763949Author:ScottChacon<schacon@gee-mail.com>Date:MonMar1721:52:112008-0700changed the version number diff--git a/Rakefileb/Rakefileindex a874b73..8f94139100644---a/Rakefile+++b/Rakefile@@-5,7+5,7@@ require 'rake/gempackagetask' spec=Gem::Specification.newdo|s|s.platform=Gem::Platform::RUBYs.name="simplegit"-s.version="0.1.0"+s.version="0.1.1"s.author="Scott Chacon"s.email="schacon@gee-mail.com"s.summary="A simple gem for using Git in Ruby code."commit085bb3bcb608e1e8451d4b2432f8ecbe6306e7e7Author:ScottChacon<schacon@gee-mail.com>Date:SatMar1516:40:332008-0700removed unnecessary test diff--git a/lib/simplegit.rb b/lib/simplegit.rb index a0a60ae..47c6340100644---a/lib/simplegit.rb+++b/lib/simplegit.rb @@-18,8+18,3@@classSimpleGitend end--if$0==__FILE__-git=SimpleGit.new-puts git.show-end \Nonewline at end of file

需要专业的网站建设服务?

联系我们获取免费的网站建设咨询和方案报价,让我们帮助您实现业务目标

立即咨询