git 如何从命令行打开 SourceTree?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19663202/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you open SourceTree from the command line?
提问by loeschg
Is there a quick and easy way to open a git repository in SourceTree from the command line?
是否有一种快速简便的方法可以从命令行在 SourceTree 中打开 git 存储库?
I do a lot of git work from Terminal, but sometimes there's no replacement for a good history view/diff. Would love to be able to open without using bookmarks.
我从终端做了很多 git 工作,但有时没有替代良好的历史视图/差异。希望能够在不使用书签的情况下打开。
回答by loeschg
Installing the SourceTree Command Line Tools will provide you with the stree
command. This will allow you to open the current directory in SourceTree.
安装 SourceTree 命令行工具将为您提供stree
命令。这将允许您在 SourceTree 中打开当前目录。
You can also specify a particular path to a repo
您还可以指定一个特定的存储库路径
stree ~/my-repo-in-another-folder
If installing command-line tools isn't an option for whatever reason, you can also do the following:
如果出于某种原因无法安装命令行工具,您还可以执行以下操作:
open -a SourceTree path-to-file
and maybe set up an alias in .bashrc or .zshrc
并可能在 .bashrc 或 .zshrc 中设置别名
alias sourcetree='open -a SourceTree'
For those who are using SourceTree 3
对于那些使用 SourceTree 3 的人
alias sourcetree='open -a SourceTree\ 3'
回答by Erik
The answer by loeschgmay not work; some people get an error referring to their system logs and cannot install the command line tools. There is an open issue about this.
loeschg 的回答可能行不通;有些人在参考他们的系统日志时遇到错误并且无法安装命令行工具。有一个关于这个的公开问题。
A workaround is found here.Use:
ln -s /Applications/SourceTree.app/Contents/Resources/stree /usr/local/bin/
This will create a symbolic link to the stree
binary and put it in /usr/local/bin
. Make sure that directory is on your path: which stree
should result in /usr/local/bin/stree
. If it does not, then add it to your PATH
manually or use echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile
, which does it for you (restart your shell to reload the PATH
variable).
这将创建一个指向stree
二进制文件的符号链接并将其放入/usr/local/bin
. 确保该目录在您的路径上:which stree
应该导致/usr/local/bin/stree
. 如果没有,则将其添加到您的PATH
手动或使用echo export PATH='/usr/local/bin:$PATH' >> ~/.bash_profile
,它会为您完成(重新启动您的外壳以重新加载PATH
变量)。
On the above-mentioned issue's page, another workaround that I didn't test was posted: alias stree='/Applications/SourceTree.app/Contents/Resources/stree'
. If you use it, please report in the comments if and how it works and why you'd prefer it over the symbolic link.
在上述问题的页面上,发布了另一个我没有测试的解决方法:alias stree='/Applications/SourceTree.app/Contents/Resources/stree'
. 如果您使用它,请在评论中报告它是否以及如何工作以及为什么您更喜欢它而不是符号链接。
For both methods, the path to stree
in SourceTree.app
must of course match the location where you installed SourceTree.app
.
对于这两种方法,stree
in的路径SourceTree.app
当然必须与您安装SourceTree.app
.
Now, stree
is installed and can be accessed from any directory. The shortest way to open SourceTree when your shell's working directory is a repository's root directory is stree .
.
现在,stree
已安装并可从任何目录访问。当 shell 的工作目录是存储库的根目录时,打开 SourceTree 的最短方法是stree .
.
回答by Sumner Evans
For those of you on Windows, you can add a batch file named stree.bat
to a folder in your PATH Environment Variable. (I have a C:\batch
folder which is in my PATH where I store all my utility batch files.) Put the following in to your batch file:
对于那些使用 Windows 的人,您可以stree.bat
在 PATH 环境变量中添加一个名为文件夹的批处理文件。(我的C:\batch
PATH 中有一个文件夹,我在其中存储了所有实用程序批处理文件。)将以下内容放入您的批处理文件中:
@echo off
start "" "C:\Program Files (x86)\Atlassian\SourceTree\SourceTree.exe"
Now you can go to any Git or Mercurial repository and run this command which will open the repository in SourceTree.
现在您可以转到任何 Git 或 Mercurial 存储库并运行此命令,这将在 SourceTree 中打开存储库。
回答by Greg Burghardt
Another Windows solution for those who use Git on the Bash command line (msys).
另一个适用于在 Bash 命令行 (msys) 上使用 Git 的用户的 Windows 解决方案。
Add two functions to your Bash .profile:
向 Bash .profile 添加两个函数:
# Courtesy: http://stackoverflow.com/questions/12015348/msys-path-conversion-or-cygpath-for-msys
function towinpath {
{ cd && pwd -W; } | sed 's|/|\|g'
}
function stree {
if [ -z ]; then
stree_path=$(towinpath pwd)
else
stree_path=$(towinpath )
fi
echo "Starting SourceTree in $stree_path"
/c/Program\ Files\ \(x86\)/Atlassian/SourceTree/SourceTree.exe -f $stree_path status
}
Reload your shell.
重新加载你的外壳。
Now you can use:
现在您可以使用:
$ towinpath /c/Temp
And it will echo c:\Temp
.
它会回声c:\Temp
。
Or you can open SourceTree:
或者你可以打开 SourceTree:
$ stree .
And it will open this repository in SourceTree defaulting to the Status panel.
它将在 SourceTree 中打开这个存储库,默认为状态面板。
回答by Yan Sern
If you have cygwin installed, you can use this as your stree.bat
. This batch file uses cygpath
to resolve .
to its absolute path, so you can do stree .
如果您安装了 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%"
回答by Dheeraj Chakilam
Windows
视窗
Adapting from multiple answers here for Windows, these scripts will allow you to get SourceTree running from command line (tested on SourceTree 3.0.1.7 / Windows 10).
根据此处针对 Windows 的多个答案改编,这些脚本将允许您从命令行运行 SourceTree(在 SourceTree 3.0.1.7 / Windows 10 上测试)。
Scripts in a PATH directory
PATH 目录中的脚本
I've placed both these scripts in a folder that is in my system PATH. You won't have to modify your bash profile for this script.
我已将这两个脚本放在系统路径中的文件夹中。您不必为此脚本修改 bash 配置文件。
Git Bash for Windows
适用于 Windows 的 Git Bash
Create a file named stree
(touch stree
) in your PATH linked directory and run chmod u+x stree
on this file.
在 PATH 链接目录中创建一个名为stree
( touch stree
)的文件并chmod u+x stree
在该文件上运行。
#!/bin/sh
function towinpath {
{ cd && pwd -W; } | sed 's|/|\|g'
}
if [ -z ]; then
stree_path=$(towinpath pwd)
else
stree_path=$(towinpath )
fi
$LOCALAPPDATA/SourceTree/SourceTree.exe -f $stree_path log &
You can replace "log" in the last line with "status" if you prefer the changes/working directory view of your repository in SourceTree.
如果您更喜欢 SourceTree 中存储库的更改/工作目录视图,则可以将最后一行中的“log”替换为“status”。
Command Prompt or Powershell
命令提示符或 Powershell
Create a file named stree.cmd
in your PATH linked directory.
创建一个stree.cmd
在 PATH 链接目录中命名的文件。
@echo off
start "" "%LOCALAPPDATA%\SourceTree\SourceTree.exe"
Note that this won't actually open up the directory as a repository.
请注意,这实际上不会将目录作为存储库打开。
Please feel free to improve the scripts, especially the one for Command Prompt.
请随时改进脚本,尤其是命令提示符的脚本。