git log 详解

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/heiyouhei123/article/details/86476925

git log 可以让我们查看提交commit history,接下来我们来一起探索git log提供的参数。

$ git log
commit 0005d1e3f54b79fe4707fbccc44b89e0fb4ce565 (HEAD -> master, origin/master, origin/HEAD)
Author: Carl Mungazi <[email protected]>
Date:   Sat Jan 12 05:46:05 2019 +0000

    Fix typo (#14576)

commit f290138d329aa7aa635d88868705b23372e9f004
Author: Brian Vaughn <[email protected]>
Date:   Thu Jan 10 12:56:52 2019 -0800

    react-debug-tools accepts currentDispatcher ref as param (#14556)

    * react-debug-tools accepts currentDispatcher ref as param

    * ReactDebugHooks injected dispatcher ref is optional

git log默认会输出commit hash, author, date, commit message.

1 --oneline

这个命令简化git log的默认的输出,仅仅输出commit hash 前7个字符串和commit message.

$ git log --oneline
0005d1e3f (HEAD -> master, origin/master, origin/HEAD) Fix typo (#14576)
f290138d3 react-debug-tools accepts currentDispatcher ref as param (#14556)
b4ad8e947 rename useImperativeMethods -> useImperativeHandle (#14565)
ab03e3d65 Inject ReactCurrentDispatcher ref to DevTools (#14550)
19ef0ec11 Separate current owner and dispatcher (#14548)

2 --stat

--stat:是在git log 的基础上输出文件增删改的统计数据。

$ git log --stat
commit 0005d1e3f54b79fe4707fbccc44b89e0fb4ce565 (HEAD -> master, origin/master, origin/HEAD)
Author: Carl Mungazi <[email protected]>
Date:   Sat Jan 12 05:46:05 2019 +0000

    Fix typo (#14576)

 packages/scheduler/src/Scheduler.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

commit f290138d329aa7aa635d88868705b23372e9f004
Author: Brian Vaughn <[email protected]>
Date:   Thu Jan 10 12:56:52 2019 -0800

    react-debug-tools accepts currentDispatcher ref as param (#14556)

    * react-debug-tools accepts currentDispatcher ref as param

    * ReactDebugHooks injected dispatcher ref is optional

 packages/react-debug-tools/src/ReactDebugHooks.js  | 42 ++++++++++++++++------
 .../ReactHooksInspection-test.internal.js          | 33 +++++++++++++++++
 ...eactHooksInspectionIntegration-test.internal.js | 35 ++++++++++++++++++
 3 files changed, 100 insertions(+), 10 deletions(-)

3 -p

-p:控制输出每个commit具体修改的内容,输出的形式以diff的形式给出。

$ git log -p
commit 0005d1e3f54b79fe4707fbccc44b89e0fb4ce565 (HEAD -> master, origin/master, origin/HEAD)
Author: Carl Mungazi <[email protected]>
Date:   Sat Jan 12 05:46:05 2019 +0000

    Fix typo (#14576)

diff --git a/packages/scheduler/src/Scheduler.js b/packages/scheduler/src/Scheduler.js
index 480ec81c4..a6e27850d 100644
--- a/packages/scheduler/src/Scheduler.js
+++ b/packages/scheduler/src/Scheduler.js
@@ -194,7 +194,7 @@ function flushWork(didTimeout) {
         firstCallbackNode !== null &&
         !(enableSchedulerDebugging && isSchedulerPaused)
       ) {
-        // TODO Wrap i nfeature flag
+        // TODO Wrap in feature flag
         // Read the current time. Flush all the callbacks that expire at or
         // earlier than that time. Then read the current time again and repeat.
         // This optimizes for as few performance.now calls as possible.

commit f290138d329aa7aa635d88868705b23372e9f004
Author: Brian Vaughn <[email protected]>
Date:   Thu Jan 10 12:56:52 2019 -0800

    react-debug-tools accepts currentDispatcher ref as param (#14556)

    * react-debug-tools accepts currentDispatcher ref as param

    * ReactDebugHooks injected dispatcher ref is optional

diff --git a/packages/react-debug-tools/src/ReactDebugHooks.js b/packages/react-debug-tools/src/ReactDebugHooks.js
index 9b5a3b499..b00df7e46 100644
--- a/packages/react-debug-tools/src/ReactDebugHooks.js
+++ b/packages/react-debug-tools/src/ReactDebugHooks.js
@@ -20,7 +20,7 @@ import {
   ForwardRef,
 } from 'shared/ReactWorkTags';

-const ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
+type CurrentDispatcherRef = typeof ReactSharedInternals.ReactCurrentDispatcher;

 // Used to track hooks called during a render

4 git show

git show命令同git log -p输出类似,只不过它只显示一个commit的内容,如果不指定commit hash, 它默认输出HEAD指向commit的内容.

$ git show
commit 0005d1e3f54b79fe4707fbccc44b89e0fb4ce565 (HEAD -> master, origin/master, origin/HEAD)
Author: Carl Mungazi <[email protected]>
Date:   Sat Jan 12 05:46:05 2019 +0000

    Fix typo (#14576)

diff --git a/packages/scheduler/src/Scheduler.js b/packages/scheduler/src/Scheduler.js
index 480ec81c4..a6e27850d 100644
--- a/packages/scheduler/src/Scheduler.js
+++ b/packages/scheduler/src/Scheduler.js
@@ -194,7 +194,7 @@ function flushWork(didTimeout) {
         firstCallbackNode !== null &&
         !(enableSchedulerDebugging && isSchedulerPaused)
       ) {
-        // TODO Wrap i nfeature flag
+        // TODO Wrap in feature flag
         // Read the current time. Flush all the callbacks that expire at or
         // earlier than that time. Then read the current time again and repeat.
         // This optimizes for as few performance.now calls as possible.

5 git shortlog

这个命令用来输出汇总信息,以作者进行分类。

[email protected] MINGW64 /h/tmp/git/react (master)
$ git shortlog
243083df (1):
      Remove unnecessary comparison; (#11215)

839 (1):
      Update Japanese translation to 75fafe1

AGCB (1):
      fix spelling error: differen -> different (#14378)

git shortlog -s:可以用来统计每个作者的commit数量

git shortlog -n:可以用来对统计的量进行倒序排列

6 --pretty

我们可以用–pretty来自定义输出的信息,
`git log --pretty="%cn committed %h on %cd""

7 --author

--author用来过滤commit,限定输出给定的用户

$ git log --author="Andrew Clark"
commit 84b86471ea12bd1f5994d878a318dcdead1137e9
Author: Andrew Clark <[email protected]>
Date:   Wed Dec 19 17:29:25 2018 -0800

    Update CHANGELOG for 16.7

commit c695b2384fecfaeaf41e951b64fae2874f28ec12
Author: Andrew Clark <[email protected]>
Date:   Wed Dec 19 17:23:14 2018 -0800

    React v16.7.0

commit 1c5aa2f23a80be137aeecc808498aedc304725bb
Author: Andrew Clark <[email protected]>
Date:   Tue Dec 18 11:09:44 2018 -0800

    Move SchedulerFeatureFlags fork to src directory to fix lint
    

8 限定log输出

直接在log命令之后,加 -n参数即可,n表示你要输出的数量.

$ git log -2
commit 0005d1e3f54b79fe4707fbccc44b89e0fb4ce565 (HEAD -> master, origin/master, origin/HEAD)
Author: Carl Mungazi <[email protected]>
Date:   Sat Jan 12 05:46:05 2019 +0000

    Fix typo (#14576)

commit f290138d329aa7aa635d88868705b23372e9f004
Author: Brian Vaughn <[email protected]>
Date:   Thu Jan 10 12:56:52 2019 -0800

    react-debug-tools accepts currentDispatcher ref as param (#14556)

    * react-debug-tools accepts currentDispatcher ref as param

    * ReactDebugHooks injected dispatcher ref is optional

9 限定指定日期范围的log

--after--before

$ git log --after '10-1-2019'
commit 0005d1e3f54b79fe4707fbccc44b89e0fb4ce565 (HEAD -> master, origin/master, origin/HEAD)
Author: Carl Mungazi <[email protected]>
Date:   Sat Jan 12 05:46:05 2019 +0000

    Fix typo (#14576)

commit f290138d329aa7aa635d88868705b23372e9f004
Author: Brian Vaughn <[email protected]>
Date:   Thu Jan 10 12:56:52 2019 -0800

    react-debug-tools accepts currentDispatcher ref as param (#14556)

    * react-debug-tools accepts currentDispatcher ref as param

    * ReactDebugHooks injected dispatcher ref is optional

commit b4ad8e947150a1a0b486a388e2d4762d3eee51ee
Author: Sunil Pai <[email protected]>
Date:   Thu Jan 10 13:37:50 2019 +0000

    rename useImperativeMethods -> useImperativeHandle (#14565)

10 控制是否显示merge的commit

--merges或者--no-merges

11 --decoreate

该参数用来控制log输出时,显示对应commit所属的branch和tag信息

$ git log --decorate --oneline
0005d1e3f (HEAD -> master, origin/master, origin/HEAD) Fix typo (#14576)
f290138d3 react-debug-tools accepts currentDispatcher ref as param (#14556)
b4ad8e947 rename useImperativeMethods -> useImperativeHandle (#14565)
ab03e3d65 Inject ReactCurrentDispatcher ref to DevTools (#14550)
19ef0ec11 Separate current owner and dispatcher (#14548)
a9b035b0c Separate Object.is polyfill (#14334)
547e059f0 Simplify wording of key warning (#14503)
3494ee57e Update ReactUpdateQueue.js (#14521)
fef40c061 Allow node 11 as devEngine (#14450)
659c13963 Update ReactFiberScheduler.js (#14477)
84b86471e Update CHANGELOG for 16.7
c695b2384 React v16.7.0
1c5aa2f23 Move SchedulerFeatureFlags fork to src directory to fix lint
653bc582f Create separate SchedulerFeatureFlags instead of using ReactFeatureFlags (#14455)
8bfef0da5 Make scheduler debugging feature flag static
4a1072194 (tag: v16.7.0) Memoize promise listeners to prevent exponential growth (#14429)

猜你喜欢

转载自blog.csdn.net/heiyouhei123/article/details/86476925
0条评论
添加一条新回复