【问题标题】:Git Commit on Mac using Sublime 2: subl command works by itself but not during a git commit使用 Sublime 2 在 Mac 上提交 Git:subl 命令单独工作,但在 git 提交期间不起作用
【发布时间】:2017-11-14 07:22:37
【问题描述】:

我正在学习 Git 的基础知识,但在尝试使用 Sublime 2 作为提交消息的默认文本编辑器时遇到了问题。

我使用的是 Mac 和 Sublime 文本编辑器(版本 2.0.2,Build 2221)

按照help.github 上的说明,我使用了以下行:

git config --global core.editor "subl -n -w"

但是,当我尝试 git commit 命令时,我收到以下消息:

subl -n -w: subl: command not found
error: There was a problem with the editor 'subl -n -w'.
Please supply the message using either -m or -F option.

我知道sublsubl -n -w 可以工作,因为我已经单独尝试过它们,它们会启动编辑器。所以问题一定是从git commit命令打开编辑器的时候。

我查看了来自123 的问题和答案,并尝试了解决方案,但未能解决我的问题。

【问题讨论】:

  • 在您的 Mac 上,subl 二进制文件在哪里?也就是说,which subl 说什么?接下来,检查当 git 运行子命令时您的 $PATH 设置为什么(例如,暂时将 core.editor 设置为 env 并运行 git config -e 或其他东西,以便您可以检查 PATH 设置)。可能您需要摆弄您的.profile.cshrc,因为它们可能会将带有subl 的目录从您的路径中移除。
  • 感谢您的帮助。抱歉,如果这不完全符合您的要求,但我是命令行新手。 i) which subl 命令没有返回任何内容。 ii) git config e 返回以下错误:env: /Users/My_Name/File_Name/.git/config: Permission denied error: There was a problem with the editor 'env'.
  • 有人在另一个论坛上发布了解决方案。命令是git config --global core.editor "'/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl' -n -w"。这是否表明错误是符号链接?如果是这样,有人可以发布建立符号链接的正确方法,以便命令git config --global core.editor "subl -n -w" 可以工作
  • 完整路径有效仍然意味着您的$PATH 是错误的,因为通常您希望直接在您的$PATH 上运行您打算运行的东西(例如.../bin/subl)。我不确定您的意思是什么符号链接,您的帖子和链接的 help.github.com 中都没有。

标签: git version-control sublimetext2 git-commit


【解决方案1】:

此答案假定 Git 和 Sublime Text 2 已正确安装。如果您尚未更新到最新版本的 Mac 版 Git,请参阅此页面:https://git-scm.com/download/mac

  1. 打开终端。
  2. 运行命令cd /usr/local/bin 并验证/usr/local/bin 是否存在。如有必要,请创建 /usr/local/bin
  3. 运行命令echo $PATH 并验证bin:/usr/local/bin 是否存在于路径中。如有必要,将bin:/usr/local/bin 添加到路径中。
  4. 运行命令ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
  5. 如果您在执行第 4 步后收到 Permission Denied 错误,请运行命令 sudo ln -s "/Applications/Sublime Text 2.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl 并在出现提示时输入您的密码。
  6. 运行命令subl 并验证 Sublime Text 2 是否打开。关闭 Sublime Text 2。
  7. 运行命令git config --global core.editor "subl -n -w"。现在应该将 Sublime Text 2 配置为 Git 提交消息的编辑器。

【讨论】:

    【解决方案2】:

    我在尝试为 Mac 上的 git commit 消息配置 Sublime Text 3 时遇到了同样的错误。和你一样,subl 终端命令启动了 Sublime Text 3,但在与 git commit 一起使用时产生了错误。

    我最初尝试git config --global core.editor "subl -n -w" 并得到:

    subl -n -w: subl: command not found
    error: There was a problem with the editor 'subl -n -w'.
    Please supply the message using either -m or -F option.
    

    然后我尝试了以下方法,将subl 替换为绝对路径:

    $ git config --global core.editor "'/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl' -n -w"
    

    并收到以下错误:

    '/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl' -n -w: /Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl: No such file or directory
    error: There was a problem with the editor ''/Applications/Sublime\ Text.app/Contents/SharedSupport/bin/subl' -n -w'.
    Please supply the message using either -m or -F option.
    

    这是因为绝对文件路径包含一个不必要的转义反斜杠。一旦我删除了反斜杠,它就起作用了! 正确的git config 命令是:

    $ git config --global core.editor "'/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl' -n -w"
    

    哒哒!

    【讨论】:

      猜你喜欢
      • 2019-12-28
      • 2018-09-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-12-20
      • 1970-01-01
      • 1970-01-01
      • 2014-02-16
      相关资源
      最近更新 更多