git 查看指定文件的修改历史记录

更新日期: 2017-06-29 阅读次数: 2254 分类: Git

使用 git 经常遇到这样的使用场景

  • 查看一个文件被哪些兄弟修改过
  • 查看一个文件近期是否发生改动

查看一个文件的历史修改记录列表

git log <file_name>

会列出 commit 的概要列表

以 weex hacknews 为例

$ git log src/views/ArticleView.vue

commit 57448f63785b3e4fe43f88b56969215c7b2325be
Author: Hanks <zhanghan.me@gmail.com>
Date:   Sat Dec 31 03:15:53 2016 +0800

    add https filter for url

commit 30c885432007ef1e8a54b7f68dc5be975feef8fb
Author: Hanks <zhanghan.me@gmail.com>
Date:   Sat Dec 31 03:05:54 2016 +0800

    add global mixin

commit adc5d7cfdf7294f261cb5a8c413b613917b29630
Author: Jinjiang <zhaojinjiang@me.com>
Date:   Fri Dec 30 01:26:42 2016 +0800

    improved <web> preview

commit c3b61ad119815f8a3975e7e6529202495714cb1a
Author: Hanks <zhanghan.me@gmail.com>
Date:   Thu Dec 22 01:34:30 2016 +0800

    modify the component dependence

commit 8d03b2419895c1ee3a564cd818cce87550a0dde5
Author: Hanks <zhanghan.me@gmail.com>
Date:   Mon Dec 19 17:33:31 2016 +0800

    [router] import vue-router

commit 14922ceb40bc7cbd35d83adcd67f57f12e6330b9
Author: Hanks <zhanghan.me@gmail.com>
Date:   Thu Dec 15 16:48:47 2016 +0800

    [vue] add artice view

如果想查看一次提交的具体修改

git show <commit>

例如

$ git show 57448f63785b3e4fe43f88b56969215c7b2325be

commit 57448f63785b3e4fe43f88b56969215c7b2325be
Author: Hanks <zhanghan.me@gmail.com>
Date:   Sat Dec 31 03:15:53 2016 +0800

    add https filter for url

diff --git a/src/filters/index.js b/src/filters/index.js
index c102984..03eb942 100644
--- a/src/filters/index.js
+++ b/src/filters/index.js
@@ -6,6 +6,13 @@ export function host (url) {
   return parts.join('.')
 }
 
+export function https (url) {
+  if (WXEnvironment.platform === 'iOS' && typeof url === 'string') {
+    return url.replace(/^http\:/, 'https:')
+  }
+  return ''
+}
+

一次性展示出所有提交的具体修改

git log -p <file_name>

爱评论不评论