博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用 vimdiff 來呈現 Git diff 差異
阅读量:4682 次
发布时间:2019-06-09

本文共 1486 字,大约阅读时间需要 4 分钟。

原文地址:

GIT diff 最近一次 commit 到此次更改的所有變動(進階參數, 暫時先不列入此範圍), 呈現結果跟一般 diff 差不多.

  • 註: 若於 .gitconfig 設定下述, 則可多加上顏色區別.

    [color]

        diff = auto

 

若想要用 vimdiff 來取代 Git diff, 要如何做呢?

(下述步驟 參考此文: )

設定 vimdiff 取代 Git diff

  1. vim /usr/local/bin/git_diff_wrapper # 此位置只要放在可被執行的路徑即可, 在此先放在 /usr/local/bin/.

    #!/bin/sh

    vimdiff "$2" "$5"

  2. chmod +x /usr/local/bin/git_diff_wrapper
  3. vim ~/.gitconfig # 下述兩行都需要加入, pager 使用 diff 的設定, diff 呼叫外部程式 git_diff_wrapper.

    [diff]

        external = git_diff_wrapper
    [pager]
        diff =

  4. 或 vim ~/.gitconfig (二者挑其一即可)

    [diff]

        external = git_diff_wrapper
    [core]
        pager =

  5. 完成.

上述完成後, 直接於修改過的專案目錄下, 輸入 git diff, 就會於 vimdiff 的畫面 顯示 差異結果.

顯示 預設 git diff 結果

若想要看原始 git diff 的結果, 可用下述做法:

  1. vim ~/.bashrc # 最後一行加入下述

    function git_diff() {

        git diff --no-ext-diff -w "$@" | vim -R -
    }

    Git diff 參數說明
    • --no-ext-diff : 不允許執行外部 diff 命令(防止 call vimdiff)
    • -w : 忽略所有空白
    • -R : 將 vim 設定於唯讀模式(read-only mode)
    • - : 讓 vim 作為 pager
    • 詳細可見: git diff --help
  2. 於修改過的專案目錄 輸入 git_diff, 就會進入 vim 編輯原始 git diff 的結果.

Vimdiff 操作快速鍵

下述部份摘錄自此篇: 

最常用的是 dp, vimdiff 會顯示左右兩個視窗, 於兩者差異處, 此區塊是要的, 就切換到要的那個視窗, 對想要的那個段落按 dp, 就會自動將此段內容複製到另外一個視窗的對應位置.

    • do - Get changes from other window into the current window.
    • dp - Put the changes from current window into the other window.
    • ]c - Jump to the next change.
    • [c - Jump to the previous change.
    • Ctrl W + Ctrl W - Switch to the other split window.
    • :diffupdate – diff update 
    • :syntax off – syntax off 
    • zo – open folded text
    • zc – close folded text

转载于:https://www.cnblogs.com/Phenix_Yang/archive/2012/10/11/2719867.html

你可能感兴趣的文章
Populating Next Right Pointers in Each Node
查看>>
CXF和Axis的比较【转】
查看>>
设计一个函数,它接受不定数量的参数,这是参数都是函数。这些函数都接受一个回调函数作为参数,按照回调函数被调用的顺序返回函数名...
查看>>
Android 轮播
查看>>
GCD介绍(三): Dispatch Sources
查看>>
Mysql 导入导出备份
查看>>
CSS绘制星星评分实现分析
查看>>
LA 3890 Most Distant Point from the Sea(半平面交)
查看>>
CF822C Hacker, pack your bags!(思维)
查看>>
软件工程第一次作业补充
查看>>
OBJECTIVE-C入门(2) 类的声明和定义
查看>>
WebTester | 本地网站调试工具
查看>>
【转】Unity ZTest 深度测试 & ZWrite 深度写入
查看>>
命令行查看数据库
查看>>
《你必须知道的495个C语言问题》知识笔记及补充
查看>>
[转]Jackson 解析json数据之忽略解析字段注解@JsonIgnoreProperties
查看>>
Android入门系列:UI组件:布局管理器:GridLayout
查看>>
白盒测试实践--Day3 12/19/2017
查看>>
写驱动的步骤
查看>>
对未来的思考(一)
查看>>