[Visual Studio] 利用內建的diff merge 進行整合

當要進行代碼整合時, 有時需要進行3-way match, 簡單說是用兩個檔期進行比對整合, 並標示有衝突(Conflict) 的部份.市面上亦有好多工具可以進行比較, 即使notepad++ 也可以透過plug-in實現. 但要用來做merge 的話就有點麻煩.  幸好Visual Studio 中有內建的指令可以使用, 方法如下:

@echo off
:: Initial settings.
set FILE_NAME=%1

:: Set vsdiffmerge parameters.
set ORIGINAL_FILE="C:\original\%FILE_NAME%"
set COMPARE_FILE="C:\compare\%FILE_NAME%"
set BASE_FILE="C:\base\%FILE_NAME%"
set TARGET_FILE="C:\merge\%FILE_NAME%"

:: Execute command.
"C:\Program Files (x86)\Microsoft Visual Studio19\Professional\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\vsdiffmerge.exe" %ORIGINAL_FILE% %COMPARE_FILE% %BASE_FILE% %TARGET_FILE%  /t /m

在示範中, 假設比較的檔案會放到original / compare 中, 而base 決定哪個是決定用哪個做基準, 而merge 後的結果則放到merge 中.

About C.H. Ling 262 Articles
a .net / Java developer from Hong Kong and currently located in United Kingdom. Thanks for Google because it solve many technical problems so I build this blog as return. Besides coding and trying advance technology, hiking and traveling is other favorite to me, so I will write down something what I see and what I feel during it. Happy reading!!!

Be the first to comment

Leave a Reply

Your email address will not be published.


*


This site uses Akismet to reduce spam. Learn how your comment data is processed.