您的位置:首页 > 其它

让SourceTree也能Export文件

2016-06-01 15:39 459 查看
从SVN转到SourceTree,在想导出几个提交版本所牵涉到的文件时, 一定会怀念SVN的Export功能。 怎么让SourceTree也有这个功能呢?

看看在TortoiseSVN里面怎么做的:

1. Show Log

2. 选择想导出的那些个Revision

3. 选择想导出的那些个文件

4. 在文件上右键, Export...

到了SourceTree里面, 我可怎么也找不到Export的命令。

好在最新版本的SourceTree支持Custom Action。 这样我们就能自己编写Export命令了。

以下是windows的bat命令, 储存为export.bat。 linux下的请按图索骥

@set export_php="C:\work\git-export\export.php"

@set export_dir="C:\WWW\export"

@set source_files=%*

@rmdir %export_dir% /s/q

@mkdir %export_dir%

@php %export_php% %source_files%

@explorer %export_dir%

以下是export.php

    <?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";

 

请修改这几个变量指向的路径:

export_php // export.php所在的位置

export_dir // 输出目录所在的位置

$source_dir // 项目文件所在的位置 -- SourceTree所掌控的目录

$exp_dir    // 输出目录所在的位置

 

最后, 在SourceTree,选择 Tools=>Options=>Custom Actions=>Add

Script to run 就是那个bat的位置。

ok即可。

 

以后只需要选择相关的commit, 选择相关的文件。 然后选择Actions=》Custom Actions=》Export... 即可。

 

导出完毕后, 会自动打开export文件夹。 挺方便的。

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: