在提交了若干更新之后,又或者克隆了某个项目,想回顾下提交历史,可以使用 git log
命令查看。
常用选项
选项 | 说明 |
---|
-p | 按补丁格式显示每个更新之间的差异 |
--word-diff | 按 word diff 格式显示差异 |
--stat | 显示每次更新的文件修改统计信息 |
--shortstat | 只显示 --stat 中最后的行数修改添加移除统计 |
--name-only | 仅在提交信息后显示已修改的文件清单 |
--name-status | 显示新增、修改、删除的文件清单 |
--abbrev-commit | 仅显示 SHA-1 的前几个字符,而非所有的 40 个字符 |
--relative-date | 使用较短的相对时间显示(比如:2 weeks ago ) |
--graph | 显示 ASCII 图形表示的分支合并历史 |
--pretty | 使用其他格式显示历史提交信息。可用的选项包括 oneline, short, full, fuller 和 format (后跟指定格式) |
--oneline | --pretty=oneline --abbrev-commit 的简化用法 |
项目准备
1
2
3
4
5
6
7
8
9
10
11
| // 此处以 vue 做演示
$ cd ~/Desktop/
$ git clone https://github.com/vuejs/vue.git
Cloning into 'vue'...
remote: Enumerating objects: 89, done.
remote: Counting objects: 100% (89/89), done.
remote: Compressing objects: 100% (64/64), done.
remote: Total 53631 (delta 38), reused 51 (delta 25), pack-reused 53542
Receiving objects: 100% (53631/53631), 25.20 MiB | 1.76 MiB/s, done.
Resolving deltas: 100% (37410/37410), done.
$ cd vue
|
普通格式查看
查看当前分支的所有简略日志
1
2
3
4
5
6
7
8
9
10
11
12
| commit 38e967b8067441ff37cb3b923200023a6b842759 (HEAD -> dev, origin/dev, origin/HEAD)
Author: Xin Du (Clark) <clark.duxin@gmail.com>
Date: Wed Dec 12 16:41:45 2018 +0000
refactor: tiny cleanup changes (#9193)
commit af9e2b3f0f4156fd52ed4444b96e2b8c0932c658
Author: Nick Hall <iamssb@gmail.com>
Date: Thu Dec 13 01:41:36 2018 +0900
chore: minor comment cleanup (#9191)
...
|
查看所有分支的所有简略日志
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| $ git log --all
commit ce35159d6d6e9c3607bd3232e386b5b994d0ec49 (origin/2.6)
Author: Evan You <yyx990803@gmail.com>
Date: Wed Dec 26 17:22:32 2018 -0500
chore: fix types
commit c7c13c2a156269d29fd9c9f8f6a3e53a2f2cac3d
Author: Evan You <yyx990803@gmail.com>
Date: Wed Dec 26 17:17:30 2018 -0500
fix(scoped-slots): ensure $scopedSlots calls always return Arrays
Also allow render functions to return an Array of a single element.
Close #8056
commit d747469e1ae26190d364e5cc9c8112d3d865a0b9
Author: Evan You <yyx990803@gmail.com>
Date: Wed Dec 26 16:02:50 2018 -0500
test: test case for v-for native collection support
...
|
查看某个文件变动的具体日志信息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| $ git log -- src/core/index.js
commit 9b22d86ab315a3c6061a6a4776eab1964304f92e
Author: Evan You <yyx990803@gmail.com>
Date: Thu Mar 8 09:51:03 2018 -0500
fix: install ssr helpers for functional context during SSR
close #7443, ref nuxt/nuxt.js#2565
commit 55816543c46e75aa53481ac95a89ff6f87a2d704
Author: JK <jingkai.zhao@foxmail.com>
Date: Thu Jun 29 12:37:03 2017 +0800
fix(ssr): reference error when create $ssrContext for root component (#5981)
fix #5941
...
|
查看某个文件变动的具体日志信息和文件内容
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| $ git log --follow -p -- src/core/index.js
commit 9b22d86ab315a3c6061a6a4776eab1964304f92e
Author: Evan You <yyx990803@gmail.com>
Date: Thu Mar 8 09:51:03 2018 -0500
fix: install ssr helpers for functional context during SSR
close #7443, ref nuxt/nuxt.js#2565
diff --git a/src/core/index.js b/src/core/index.js
index b2a0cb8c..daf6203b 100644
--- a/src/core/index.js
+++ b/src/core/index.js
@@ -1,6 +1,7 @@
import Vue from './instance/index'
import { initGlobalAPI } from './global-api/index'
import { isServerRendering } from 'core/util/env'
+import { FunctionalRenderContext } from 'core/vdom/create-functional-component'
...
|
查看最近两次更新的内容差异
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
| $ git log -p -2
commit 38e967b8067441ff37cb3b923200023a6b842759 (HEAD -> dev, origin/dev, origin/HEAD)
Author: Xin Du (Clark) <clark.duxin@gmail.com>
Date: Wed Dec 12 16:41:45 2018 +0000
refactor: tiny cleanup changes (#9193)
diff --git a/src/core/instance/events.js b/src/core/instance/events.js
index 8225bdec..bb07a96b 100644
--- a/src/core/instance/events.js
+++ b/src/core/instance/events.js
@@ -102,16 +102,14 @@ export function eventsMixin (Vue: Class<Component>) {
vm._events[event] = null
return vm
}
- if (fn) {
- // specific handler
- let cb
- let i = cbs.length
- while (i--) {
- cb = cbs[i]
- if (cb === fn || cb.fn === fn) {
- cbs.splice(i, 1)
- break
- }
+ // specific handler
+ let cb
+ let i = cbs.length
+ while (i--) {
+ cb = cbs[i]
+ if (cb === fn || cb.fn === fn) {
+ cbs.splice(i, 1)
+ break
}
}
return vm
...
|
查看最近的三条的简略日志
1
2
3
4
| $ git log --oneline -n3
38e967b8 (HEAD -> dev, origin/dev, origin/HEAD) refactor: tiny cleanup changes (#9193)
af9e2b3f chore: minor comment cleanup (#9191)
b06c784b fix(ssr): support rendering comment (#9128)
|
显示简要的增改行数统计
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| $ git log --stat
commit 38e967b8067441ff37cb3b923200023a6b842759 (HEAD -> dev, origin/dev, origin/HEAD)
Author: Xin Du (Clark) <clark.duxin@gmail.com>
Date: Wed Dec 12 16:41:45 2018 +0000
refactor: tiny cleanup changes (#9193)
src/core/instance/events.js | 18 ++++++++----------
src/core/util/debug.js | 2 +-
src/server/template-renderer/index.js | 2 +-
3 files changed, 10 insertions(+), 12 deletions(-)
commit af9e2b3f0f4156fd52ed4444b96e2b8c0932c658
Author: Nick Hall <iamssb@gmail.com>
Date: Thu Dec 13 01:41:36 2018 +0900
chore: minor comment cleanup (#9191)
src/core/observer/dep.js | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
commit b06c784b81a244e1bc2d028216fcd2ab873730b9
Author: Xin Du (Clark) <clark.duxin@gmail.com>
Date: Wed Dec 12 16:41:08 2018 +0000
fix(ssr): support rendering comment (#9128)
src/server/optimizing-compiler/codegen.js | 6 +++++-
test/unit/modules/server-compiler/compiler-options.spec.js | 13 +++++++++++++
2 files changed, 18 insertions(+), 1 deletion(-)
|
显示最后一次提交信息
1
2
3
4
5
6
| $ git log -1 HEAD
commit 38e967b8067441ff37cb3b923200023a6b842759 (HEAD -> dev, origin/dev, origin/HEAD)
Author: Xin Du (Clark) <clark.duxin@gmail.com>
Date: Wed Dec 12 16:41:45 2018 +0000
refactor: tiny cleanup changes (#9193)
|
查看文件改变信息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
| $ git log --name-status
commit 38e967b8067441ff37cb3b923200023a6b842759 (HEAD -> dev, origin/dev, origin/HEAD)
Author: Xin Du (Clark) <clark.duxin@gmail.com>
Date: Wed Dec 12 16:41:45 2018 +0000
refactor: tiny cleanup changes (#9193)
M src/core/instance/events.js
M src/core/util/debug.js
M src/server/template-renderer/index.js
commit af9e2b3f0f4156fd52ed4444b96e2b8c0932c658
Author: Nick Hall <iamssb@gmail.com>
Date: Thu Dec 13 01:41:36 2018 +0900
chore: minor comment cleanup (#9191)
M src/core/observer/dep.js
commit b06c784b81a244e1bc2d028216fcd2ab873730b9
Author: Xin Du (Clark) <clark.duxin@gmail.com>
Date: Wed Dec 12 16:41:08 2018 +0000
fix(ssr): support rendering comment (#9128)
M src/server/optimizing-compiler/codegen.js
A test/unit/modules/server-compiler/compiler-options.spec.js
|
指定格式查看
git log --pretty=format
常用的选项:
选项 | 说明 |
---|
%H | 提交对象(commit )的完整哈希字串 |
%h | 提交对象的简短哈希字串 |
%T | 树对象(tree)的完整哈希字串 |
%t | 树对象的简短哈希字串 |
%P | 父对象(parent)的完整哈希字串 |
%p | 父对象的简短哈希字串 |
%an | 作者(author)的名字 |
%ae | 作者的电子邮件地址 |
%ad | 作者修订日期(可以用 -date= 选项定制格式) |
%ar | 作者修订日期,按多久以前的方式显示 |
%cn | 提交者(committer)的名字 |
%ce | 提交者的电子邮件地址 |
%cd | 提交日期 |
%cr | 提交日期,按多久以前的方式显示 |
%s | 提交说明 |
git log
输出的选项:
选项 | 说明 |
---|
-(n) | 仅显示最近的 n 条提交 |
--since, --after | 仅显示指定时间之后的提交 |
--until, --before | 仅显示指定时间之前的提交 |
--author | 仅显示指定作者相关的提交 |
--committer | 仅显示指定提交者相关的提交 |
--grep | 仅显示含指定关键字的提交 |
-S | 仅显示添加或移除了某个关键字的提交 |
用 oneline 将每个提交放在一行显示
这在提交数很大时非常有用。另外还有 short
,full
和 fuller
可选。
1
2
3
4
5
6
| $ git log --pretty=oneline
38e967b8067441ff37cb3b923200023a6b842759 (HEAD -> dev, origin/dev, origin/HEAD) refactor: tiny cleanup changes (#9193)
af9e2b3f0f4156fd52ed4444b96e2b8c0932c658 chore: minor comment cleanup (#9191)
b06c784b81a244e1bc2d028216fcd2ab873730b9 fix(ssr): support rendering comment (#9128)
70754084ec2d84e44effeb8f82efda3397a08b0d (tag: v2.5.21) build: release 2.5.21
...
|
自定义格式查看日志
1
2
3
4
5
6
7
8
9
10
11
12
| $ git log --pretty=format:"%h - %an, %ar : %s"
38e967b8 - Xin Du (Clark), 3 weeks ago : refactor: tiny cleanup changes (#9193)
af9e2b3f - Nick Hall, 3 weeks ago : chore: minor comment cleanup (#9191)
b06c784b - Xi n Du (Clark), 3 weeks ago : fix(ssr): support rendering comment (#9128)
70754084 - Evan You, 3 weeks ago : build: release 2.5.21
$ git log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
* 38e967b8 - (HEAD -> dev, origin/dev, origin/HEAD) refactor: tiny cleanup changes (#9193) (3 weeks ago) <Xin Du (Clark)>
* af9e2b3f - chore: minor comment cleanup (#9191) (3 weeks ago) <Nick Hall>
* b06c784b - fix(ssr): support rendering comment (#9128) (3 weeks ago) <Xin Du (Clark)>
* 70754084 - (tag: v2.5.21) build: release 2.5.21 (3 weeks ago) <Evan You>
* b449e17e - build: build 2.5.21 (3 weeks ago) <Evan You>
|
图文格式查看
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| $ git log --pretty=oneline --graph --abbrev-commit
* 5f737e836e (HEAD -> master, origin/master, origin/HEAD) feature #29613 [VarDumper] Use hyperlinks in CliDescriptor (ogizanagi)
|\
| * e54e21933a [VarDumper] Use hyperlinks in CliDescriptor
* | 55113775c0 Merge branch '4.2'
|\ \
| * | 9ade0a7605 [Cache] fix test
* | | 96285882cf Merge branch '4.2'
|\ \ \
| |/ /
| * | 43dfbe2df9 bug #29648 [Cache] fix Simple\Psr6Cache proxying of metadata (nicolas-grekas)
| |\ \
| | * | 02edc9b049 [Cache] fix Simple\Psr6Cache proxying of metadata
| |/ /
$ git log --pretty=format:"%h %s" --graph
* 5f737e836e feature #29613 [VarDumper] Use hyperlinks in CliDescriptor (ogizanagi)
|\
| * e54e21933a [VarDumper] Use hyperlinks in CliDescriptor
* | 55113775c0 Merge branch '4.2'
|\ \
| * | 9ade0a7605 [Cache] fix test
* | | 96285882cf Merge branch '4.2'
|
通过 ASCII 树形结构来展示所有的分支
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| $ git log --graph --oneline --decorate --all
* 17d7a5f6 chore: update sponsors
| * c8139015 (origin/feat-scoped-slot-passdown) test: add slot test case (#8344)
| * bb06c75e feat(core): support passing down scopedSlots with v-bind
| | * 636c9b4e (tag: v2.5.17, origin/hotfix) build: release 2.5.17
| | * 7e75b79b build: build 2.5.17
| | * b3c5e642 chore: minor tweaks
| | * c28f7929 fix: fix potential xss vulnerability in ssr
| |/
|/|
* | 25342194 (tag: v2.5.16) build: release 2.5.16
* | 90891709 build: build 2.5.16
* | 62a922e8 fix: fix wrongly matched named slots in functional components
| | * 0f4e6a9a (origin/fix-component-insert-order) fix: invoke component node create hooks before insertion
| |/
|/|
| | * 531cea58 (origin/perf-computed) perf: avoid unnecessary re-renders when computed property value did not change
| |/
|/|
| | * ca2e6a74 (origin/fix-beforeupdate) fix: beforeUpdate should be called before render and allow state mutation
| |/
|/|
|
限制格式输出
选项 | 说明 |
---|
-(n) | 仅显示最近的 n 条提交 |
--since, --after | 仅显示指定时间之后的提交 |
--until, --before | 仅显示指定时间之前的提交 |
--author | 仅显示指定作者相关的提交 |
--committer | 仅显示指定提交者相关的提交 |
显示三周之后的提交
1
2
3
4
5
6
7
8
9
10
11
12
| $ git log --after=3.weeks
commit 38e967b8067441ff37cb3b923200023a6b842759 (HEAD -> dev, origin/dev, origin/HEAD)
Author: Xin Du (Clark) <clark.duxin@gmail.com>
Date: Wed Dec 12 16:41:45 2018 +0000
refactor: tiny cleanup changes (#9193)
commit af9e2b3f0f4156fd52ed4444b96e2b8c0932c658
Author: Nick Hall <iamssb@gmail.com>
Date: Thu Dec 13 01:41:36 2018 +0900
chore: minor comment cleanup (#9191)
|
显示两周之前的提交
1
2
3
4
5
6
7
8
9
10
11
12
| $ git log --before=2.weeks
commit 38e967b8067441ff37cb3b923200023a6b842759 (HEAD -> dev, origin/dev, origin/HEAD)
Author: Xin Du (Clark) <clark.duxin@gmail.com>
Date: Wed Dec 12 16:41:45 2018 +0000
refactor: tiny cleanup changes (#9193)
commit af9e2b3f0f4156fd52ed4444b96e2b8c0932c658
Author: Nick Hall <iamssb@gmail.com>
Date: Thu Dec 13 01:41:36 2018 +0900
chore: minor comment cleanup (#9191)
|
显示指定人提交日志
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| // 查看 2018 年元月期间,Evan You 提交的但未合并的位于项目 ./src 目录下的代码
$ git log --pretty="%h - %s" --author='Evan You' --after="2018-12-01" \
--before="2018-12-31" --no-merges -- ./src
847e4937 - fix: fix single v-for child optimization
4074104f - perf: skip normalization on single child element v-for
47487607 - fix: fix v-for component with undefined value
0d4b35f5 - fix(vdom): remove unnecessary sameVnode condition
5d721a42 - revert: fix(sfc): avoid deindent when pad option is specified (#7647)
780dac56 - fix(ssr): should not warn for custom directives that do not have ssr implementation
8a2dbf50 - fix(transition-group): fix activeInstance regression
f077ed17 - fix(ssr): fix ssr template publicPath generation
1b4a8a0c - fix(compiler): fix codegen for v-for component inside template
e4b1b57f - fix(ssr): adjust call stack size defer threshold
530ca1b2 - fix(core): properly handle reused vnodes
097f6229 - fix(core): avoid mutating original children when cloning vnode
$ git log --before={2,weeks,ago} --after={2018-11-30} --oneline
38e967b8 (HEAD -> dev, origin/dev, origin/HEAD) refactor: tiny cleanup changes (#9193)
af9e2b3f chore: minor comment cleanup (#9191)
b06c784b fix(ssr): support rendering comment (#9128)
70754084 (tag: v2.5.21) build: release 2.5.21
b449e17e build: build 2.5.21
...
|