從SVN轉到SourceTree,在想導出幾個提交版本所牽涉到的文件時, 必定會懷念SVN的Export功能。 怎麼讓SourceTree也有這個功能呢?
看看在TortoiseSVN裏面怎麼作的: php
到了SourceTree裏面, 我可怎麼也找不到Export的命令。
好在最新版本的SourceTree支持Custom Action。 這樣咱們就能本身編寫Export命令了。
如下是windows的bat命令, 儲存爲export.bat。 linux下的請按圖索驥 linux
@set export_php="E:\projects\sia\tools\export.php" @set export_dir="E:\projects\sia\export" @set source_files=%* @rmdir %export_dir% /s/q @mkdir %export_dir% @php %export_php% %source_files% @explorer %export_dir%
如下是E:\projects\sia\tools\export.php windows
<?php date_default_timezone_set('Asia/Shanghai'); if($argc == 0) { exit('Nothing to copy'); } define('DS', DIRECTORY_SEPARATOR); // I always use this short form in my code. $source_dir = 'E:'.DS.'projects'.DS.'sia'.DS.'sia'; $exp_dir = 'E:'.DS.'projects'.DS.'sia'.DS.'export'; function ExportOneFile($path) { global $source_dir,$exp_dir; $final_source = $source_dir.DS.$path; $final_dest = $exp_dir.DS.$path; $final_dest_dir = dirname($final_dest).DS; if(!is_dir($final_dest_dir)) { mkdir($final_dest_dir,0777,true); } return copy($final_source,$final_dest); } foreach($argv as $index=>$path) { if($index === 0) { continue; } if(ExportOneFile($path)) { echo $index.' : '.$path." exported\n"; } } echo "All Complete. Please go to $exp_dir to view files";
請修改這幾個變量指向的路徑: bash
export_php // export.php所在的位置 export_dir // 輸出目錄所在的位置
$source_dir // 項目文件所在的位置 -- SourceTree所掌控的目錄 $exp_dir // 輸出目錄所在的位置
最後, 在SourceTree,選擇 Tools=>Options=>Custom Actions=>Add this
Script to run 就是那個bat的位置。 spa
ok便可。 code
之後只須要選擇相關的commit, 選擇相關的文件。 而後選擇Actions=》Custom Actions=》Export... 便可。 orm
導出完畢後, 會自動打開export文件夾。 挺方便的。 ip