使用 vimdiff 來呈現 Git diff 差異
2012-10-11 14:16
597 查看
原文地址:http://blog.longwin.com.tw/2009/11/vimdiff-vs-git-diff-2009/
GIT diff 最近一次 commit 到此次更改的所有變動(進階參數, 暫時先不列入此範圍), 呈現結果跟一般 diff 差不多.
註: 若於 .gitconfig 設定下述, 則可多加上顏色區別.
[color]
diff = auto
若想要用 vimdiff 來取代 Git diff, 要如何做呢?
(下述步驟 參考此文: Git Diff with Vimdiff)
#!/bin/sh
vimdiff "$2" "$5"
chmod +x /usr/local/bin/git_diff_wrapper
vim ~/.gitconfig # 下述兩行都需要加入, pager 使用 diff 的設定, diff 呼叫外部程式 git_diff_wrapper.
[diff]
external = git_diff_wrapper
[pager]
diff =
或 vim ~/.gitconfig (二者挑其一即可)
[diff]
external = git_diff_wrapper
[core]
pager =
完成.
上述完成後, 直接於修改過的專案目錄下, 輸入 git diff, 就會於 vimdiff 的畫面 顯示 差異結果.
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
於修改過的專案目錄 輸入 git_diff, 就會進入 vim 編輯原始 git diff 的結果.
最常用的是 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
GIT diff 最近一次 commit 到此次更改的所有變動(進階參數, 暫時先不列入此範圍), 呈現結果跟一般 diff 差不多.
註: 若於 .gitconfig 設定下述, 則可多加上顏色區別.
[color]
diff = auto
若想要用 vimdiff 來取代 Git diff, 要如何做呢?
(下述步驟 參考此文: Git Diff with Vimdiff)
設定 vimdiff 取代 Git diff
vim /usr/local/bin/git_diff_wrapper # 此位置只要放在可被執行的路徑即可, 在此先放在 /usr/local/bin/.#!/bin/sh
vimdiff "$2" "$5"
chmod +x /usr/local/bin/git_diff_wrapper
vim ~/.gitconfig # 下述兩行都需要加入, pager 使用 diff 的設定, diff 呼叫外部程式 git_diff_wrapper.
[diff]
external = git_diff_wrapper
[pager]
diff =
或 vim ~/.gitconfig (二者挑其一即可)
[diff]
external = git_diff_wrapper
[core]
pager =
完成.
上述完成後, 直接於修改過的專案目錄下, 輸入 git diff, 就會於 vimdiff 的畫面 顯示 差異結果.
顯示 預設 git diff 結果
若想要看原始 git diff 的結果, 可用下述做法: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
於修改過的專案目錄 輸入 git_diff, 就會進入 vim 編輯原始 git diff 的結果.
Vimdiff 操作快速鍵
下述部份摘錄自此篇: Quick and Dirty : Vimdiff Tutorial最常用的是 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
相关文章推荐
- 使用 vimdiff 來呈現 Git diff 差異
- 如何使用 vimdiff 来 git diff 和merge diff
- git 使用vimdiff 格式显示比对文件
- 如何使用 vimdiff 来 git diff
- Git for Windows 如何使用vim作为diff工具
- 设置git使用vimdiff比较差异
- [git]使用vimdiff做git代码比较
- 使用vimdiff查看git的差异
- 如何使用 vimdiff 来 git diff /svn diff
- git 使用vimdiff比较文件差异
- vim vimdiff diff 使用及命令
- 使用vim diff 让svn diff 更直观
- 使用pathogen管理Vim插件并托管到Github 参照文章【1】【2】的办法,将vim打造成一个Python开发环境。文章中使用的是 pathogen + git 来管理 Vim 插件的。对这种
- 使用vimdiff作为svn diff的查看代码工具
- 技巧:Vimdiff 使用
- git 使用beyond compare来diff与merge
- 让GIT DIFF/MERGE使用MELD等GUI对比工具
- 使用vimdiff比较文档
- 技巧:Vimdiff 使用
- vimdiff 命令使用技巧