Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git commit does not open editor

I have a problem in which whenever I run git commit this shows up:

error: cannot spawn subl: No such file or directory
error: unable to start editor 'subl'
Please supply the message using either -m or -F option.

subl is an alias for sublime. I am running git Bash on Win10.
If I just run 'subl', it opens the editor without a problem, but with git commit it doesn't. Here is my git config file:

[core]
    editor = subl -w -n
like image 820
Lucas Rebelo Avatar asked Jul 16 '16 05:07

Lucas Rebelo


People also ask

How do you commit without opening an editor?

Use the selected commit message without launching an editor. For example, git commit --amend --no-edit amends a commit without changing its commit message. Replace the tip of the current branch by creating a new commit.

How do I change git editor?

The command to do this is git config --global core. editor "nano" . You can change the highlighted section with your editor of choice!


3 Answers

Execute git config --global core.editor "\"C:\Program Files\Sublime Text 3\sublime_text.exe\" %*" to configure Sublime as your editor in Windows.

EDIT: The above assumes you have Sublime 3 installed. If you have Sublime 2 installed, change the full path to the correct valid path to sublime_text.exe.

like image 94
player87 Avatar answered Sep 23 '22 09:09

player87


Shell aliases are a feature of the shell and not of the operating system. They can therefore only be executed directly by the shell, and not through any external tools like git.

For the same reason you can not use aliases with find -exec, xargs or sudo.

If you want a shorter way to run something that also works with external tools, create a shell script with that name instead.

like image 40
that other guy Avatar answered Sep 23 '22 09:09

that other guy


Try setting the whole path to subl like /usr/local/bin/subl or whatever it is on your system. You can find out by executing which subl in your terminal.

It's possible that whatever env your git is running in, it's not aware of your aliases.

like image 43
Vidur Avatar answered Sep 25 '22 09:09

Vidur