无法在 Windows 上使用 cygwin 启动 git gui

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9393462/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 13:02:01  来源:igfitidea点击:

Cannot launch git gui using cygwin on windows

gitcygwintclx11tk

提问by Stijn Vanpoucke

I used to launch git gui within my cygwin console without any problems but since I updated cygwin I've got the following error message:

我曾经在我的 cygwin 控制台中启动 git gui 没有任何问题,但自从我更新了 cygwin 我收到以下错误消息:

$ git gui
Application initialization failed: no display name and no $DISPLAY environment variable
Error in startup script: invalid command name "tk_messageBox"
    while executing
"tk_messageBox  -icon error  -type ok  -title "git-gui: fatal error"  -message $err"
    invoked from within
"if {[catch {package require Tcl 8.4} err]
 || [catch {package require Tk  8.4} err]
} {
        catch {wm withdraw .}
        tk_messageBox \
                -icon error \
                -typ..."
    (file "/usr/lib/git-core/git-gui" line 34)

Anyone who knows how to solve this?

有谁知道如何解决这个问题?

回答by me_and

Edit: Brought up to date in March 2016 to account for renamed packages etc.

编辑:在 2016 年 3 月更新以说明重命名的软件包等。

Cygwin's gitk and git gui require X11. This means you need to install some of the Cygwin X11 packages and set them up to be able to open the GUI.

Cygwin 的 gitk 和 git gui 需要 X11。这意味着您需要安装一些 Cygwin X11 包并将它们设置为能够打开 GUI。

This should get you up and running:

这应该能让你启动并运行:

  1. Run the Cygwin installer again (download the relevant setup-*.exeagain if you need to).
  2. At the package list, select to install "xinit" under the X11 category. Click next, accept all the dependencies, and install.
  3. In the Windows Start menu, you should have a new group: Cygwin-X. From there, run XWin Server.
  4. In your Cygwin shell, run export DISPLAY=:0.0.
  1. 再次运行 Cygwin 安装程序(如果需要,请再次下载相关的setup-*.exe)。
  2. 在软件包列表中,选择安装 X11 类别下的“xinit”。单击下一步,接受所有依赖项,然后安装。
  3. 在 Windows 开始菜单中,您应该有一个新组:Cygwin-X。从那里,运行 XWin 服务器。
  4. 在 Cygwin shell 中,运行export DISPLAY=:0.0.

You'll need to repeat step 3 every time you reboot your computer, and step 4 every time you open a new Cygwin shell (or just run echo "export DISPLAY=:0.0" >>~/.profileto have it run automatically whenever you create a new shell).

每次重新启动计算机时都需要重复第 3 步,每次打开新的 Cygwin shell 时都需要重复第 4 步(或者echo "export DISPLAY=:0.0" >>~/.profile只要在创建新 shell 时运行它就可以自动运行)。

In the comments, it seems some people are getting errors stating 'couldn't connect to display ":0.0"'. If you get that, mouse over the X that should have appeared in your system tray (you may need to click the little up icon if the X icon has been hidden); the pop-up title should say something like "Cygwin/X Server:1.0". Use that ":1.0" (or whatever you see) as the value for DISPLAYin step 4, rather than ":0.0", making sure to include the colon.

在评论中,似乎有些人收到错误,指出“无法连接到显示“:0.0””。如果你明白了,请将鼠标悬停在应该出现在系统托盘中的 X 上(如果 X 图标已隐藏,您可能需要单击向上的小图标);弹出的标题应该是“Cygwin/X Server:1.0”之类的。使用“:1.0”(或您看到的任何内容)作为DISPLAY第 4 步中的值,而不是“:0.0”,确保包含冒号。

If you have any other problems starting the X server, you will probably find you have a file called ~/.xsession-errors; check out the contents of that for what's going wrong. Also check whether you have a ~/.startxwinrcfile, and try deleting it and seeing if that fixes the problem.

如果您在启动 X 服务器时遇到任何其他问题,您可能会发现有一个名为~/.xsession-errors;的文件。查看其中的内容以了解出了什么问题。还要检查您是否有~/.startxwinrc文件,然后尝试删除它并查看是否可以解决问题。

For the interested, the reason the X11 packages aren't installed automatically is that they're not technically needed: it's possible through somewhat convoluted means to use a different X11 server than the one Cygwin installs when you install the "xinit" package.

对于感兴趣的人来说,没有自动安装 X11 包的原因是它们在技术上不是必需的:可以通过某种复杂的方式使用与安装“xinit”包时 Cygwin 安装的服务器不同的 X11 服务器。

回答by David Kartik

After spending more time than I'd care to admit, I managed to find a working solution to execute gitkfrom my cygwin shell. I couldn't get any of the instructions with starting the X server to work reliably, and in the end, the solution was pretty simple.

在花了比我愿意承认的更多的时间之后,我设法找到了一个可行的解决方案来gitk从我的 cygwin shell执行。我无法获得任何有关启动 X 服务器以使其可靠工作的说明,最后,解决方案非常简单。

The largest caveat is needing to have Git for Windows installed, the download for that can be found here.

最大的警告是需要安装适用于 Windows 的 Git,可以在此处找到下载。

Now for the whole running gitkpart. Git for windows includes a cmd folder, that has a gitk.cmdwindows command file. That's all you need to call to have gitkopen.

现在是整个运行gitk部分。Windows 版 Git 包含一个 cmd 文件夹,其中包含一个gitk.cmdWindows 命令文件。这就是您需要拨打电话才能gitk打开的全部内容。

$ [path-to-git]/cmd/gitk.cmd

On my system the Git path is in "C:\Program Files (x86)\Git" so the command would look like this:

在我的系统上,Git 路径位于“C:\Program Files (x86)\Git”中,因此命令如下所示:

$ "/cygdrive/c/Program Files (x86)/Git/cmd/gitk.cmd"

In my ~/.bash_profile I've added a function to handle that call which looks like this:

在我的 ~/.bash_profile 中,我添加了一个函数来处理该调用,如下所示:

gitk() {
  "/cygdrive/c/Program Files (x86)/Git/cmd/gitk.cmd"
}

Hope this helps someone else trying to figure this piece out.

希望这有助于其他人试图弄清楚这一点。

回答by tititou36

echo "export DISPLAY=:0.0" >>~/.profile

or

或者

echo "export DISPLAY=:0.0" >>~/.bash_profile

in my case

就我而言

回答by AndrewD

Avoid X11 and add git guisupport to cygwin

避免使用 X11 并添加git gui对 cygwin 的支持

If you want to avoid X11 (and who wouldn't?):

如果你想避免 X11(谁不想?):

  1. Install Git for Windows (non-cygwin) http://git-scm.com/download/win
  2. Open its command shell C:\Program Files (x86)\Git\Git Bash
  3. run git gui
  1. 为 Windows 安装 Git(非 cygwin)http://git-scm.com/download/win
  2. 打开它的命令外壳 C:\Program Files (x86)\Git\Git Bash
  3. git gui

(optional)If you want to stay in cygwin to launch git gui, add a function in your ~/.bashrcto do it. The only caveat is do notname the function gitbecause of recursion and confusion with arguments, and the fact that you're Git for Windows shell may also be adding the same function when it starts. You may also run into path issues so be careful about setting up your paths correctly.

(可选)如果您想留在 cygwin 中启动git gui,请在您的中添加一个函数~/.bashrc来执行。唯一的警告是不要命名函数,git因为递归和参数混淆,而且你是 Git for Windows shell 的事实也可能在它启动时添加相同的函数。您也可能会遇到路径问题,因此请注意正确设置路径。

# call git gui from Git For Windows path with `ggui`
    gg() { 
    command "/cygdrive/c/Program Files (x86)/Git/bin/git" gui  2>/dev/null;


    }

When you're done editing your .bashrc, refresh your settings:

完成 .bashrc 编辑后,刷新设置:

source ~./bashrc

and then simply:

然后简单地:

gg

回答by Minnie Shi

After following the 4 steps given by me_and and tititou36, you may still have issues of the XWin just die after you started the XwinServer.

按照me_and和tiitou36给出的4个步骤之后,你可能仍然有XWin在你启动XwinServer后就死掉的问题。

The reason is it relies on a CygWin terminal/console, which is the host, and the Xwin dies if there is no CygWin console.

原因是它依赖于作为主机的 CygWin 终端/控制台,如果没有 CygWin 控制台,Xwin 就会死机。

The solution for this is:

对此的解决方案是:

Start a Cygwin console. (you can make it automatically start by putting minttycommand into the file .startxwinrcunder your cygwin home directory.

启动 Cygwin 控制台。(您可以通过将mintty命令放入.startxwinrccygwin 主目录下的文件来使其自动启动。

回答by smac89

Here is what worked for me:

这是对我有用的:

cat >> ~/.bash_profile <<< "export DISPLAY=:0.0"

cat >> ~/.bash_profile <<< "export DISPLAY=:0.0"

From cygwin package manager, do the following:

在 cygwin 包管理器中,执行以下操作:

install xorg-serverand some xorg fonts, xorg-x11-fonts-Type1especially

安装xorg-server和一些 xorg 字体,xorg-x11-fonts-Type1尤其是

Next create a link to windows font folders for git guito use

接下来创建一个指向 Windows 字体文件夹的链接以供git gui使用

ln -s /cygdrive/c/Windows/Fonts /usr/share/fonts/win-fonts

ln -s /cygdrive/c/Windows/Fonts /usr/share/fonts/win-fonts

Close the cygwin terminal and open again then type

关闭cygwin终端并再次打开然后输入

startxwin &> /dev/null &

startxwin &> /dev/null &

git gui &

git gui &

回答by C-Otto

Based on AndrewD's answer: Use cygwin's git, but use Windows Git's gitkand git gui. In other words, uninstall the git-gui and gitk packages from cygwin (if installed). Then which gitkshould point to the Windows file, not the cygwin binary in /usr/bin.

基于 AndrewD 的回答:使用 cygwin 的git,但使用 Windows Git 的gitkgit gui. 换句话说,从 cygwin(如果已安装)卸载 git-gui 和 gitk 包。然后which gitk应该指向 Windows 文件,而不是/usr/bin.