如何从命令行打开SourceTree?

时间:2013-10-29 15:54:23

标签: git command-line atlassian-sourcetree

有没有一种从命令行在SourceTree中打开git存储库的快捷方法?

我从终端做了很多git工作,但有时候没有替代好的历史视图/差异。希望能够在不使用书签的情况下打开。

5 个答案:

答案 0 :(得分:91)

安装SourceTree命令行工具将为您提供stree命令。这将允许您在SourceTree中打开当前目录。

sourcetree commandline tools

您还可以指定回购的特定路径

stree ~/my-repo-in-another-folder

如果无论出于何种原因安装命令行工具都不是一个选项,您还可以执行以下操作:

open -a SourceTree path-to-file

并且可能在.bashrc或.zshrc

中设置别名
alias sourcetree='open -a SourceTree'

对于使用SourceTree 3的人

alias sourcetree='open -a SourceTree\ 3'

答案 1 :(得分:8)

对于Windows上的用户,可以将名为stree.bat的批处理文件添加到PATH环境变量中的文件夹中。 (我有一个C:\batch文件夹,它位于我的PATH中,我存储了所有实用程序批处理文件。)将以下内容放入批处理文件中:

@echo off
start "" "C:\Program Files (x86)\Atlassian\SourceTree\SourceTree.exe"

现在您可以访问任何Git或Mercurial存储库并运行此命令,该命令将在SourceTree中打开存储库。

答案 2 :(得分:5)

另一种Windows解决方案,适用于在Bash命令行(msys)上使用Git的用户。

向Bash .profile添加两个函数:

# Courtesy: http://stackoverflow.com/questions/12015348/msys-path-conversion-or-cygpath-for-msys
function towinpath {
    { cd $1 && pwd -W; } | sed 's|/|\\|g'
}

function stree {
    if [ -z $1 ]; then
        stree_path=$(towinpath pwd)
    else
        stree_path=$(towinpath $1)
    fi

    echo "Starting SourceTree in $stree_path"

    /c/Program\ Files\ \(x86\)/Atlassian/SourceTree/SourceTree.exe -f $stree_path status
}

重新加载你的shell。

现在你可以使用:

$ towinpath /c/Temp

它会回显c:\Temp

或者你可以打开SourceTree:

$ stree .

它将在SourceTree中打开此存储库默认为“状态”面板。

答案 3 :(得分:1)

如果您安装了cygwin,则可以将其用作stree.bat。此批处理文件使用cygpath.解析为其绝对路径,因此您可以执行stree .

@echo off
FOR /F "tokens=* USEBACKQ" %%F IN (`cygpath -w -a %1`) DO (
SET STREE_OPEN_PATH=%%F
)
%USERPROFILE%\AppData\Local\SourceTree\SourceTree.exe -f "%STREE_OPEN_PATH%"

答案 4 :(得分:0)

Windows

这些脚本适用于Windows,可通过这些脚本使您从命令行运行SourceTree(在SourceTree 3.0.1.7/Windows 10上进行了测试)。

PATH目录中的脚本

我将这两个脚本都放置在系统PATH的文件夹中。您无需为此脚本修改bash配置文件。

适用于Windows的Git Bash

在PATH链接目录中创建一个名为97stree)的文件,然后对该文件运行touch stree

chmod u+x stree

如果您更喜欢SourceTree中存储库的更改/工作目录视图,则可以用“状态”替换最后一行中的“日志”。

命令提示符或Powershell

在PATH链接目录中创建一个名为#!/bin/sh function towinpath { { cd $1 && pwd -W; } | sed 's|/|\\|g' } if [ -z $1 ]; then stree_path=$(towinpath pwd) else stree_path=$(towinpath $1) fi $LOCALAPPDATA/SourceTree/SourceTree.exe -f $stree_path log & 的文件。

stree.cmd

请注意,这实际上不会打开目录作为存储库。

请随时改进脚本,尤其是用于命令提示符的脚本。

相关问题