I'm using git under cygwin but it's not passing the correct path to my editor for commit messages.
I'm working in a test repository located on my drive at:
d:\X\git\myproject
in the cygwin terminal it shows this path as:
/cygdrive/d/X/git/myproject
When I commit without the -m flag (so that it opens up my editor for me to enter a message), my editor tries to write a file to the wrong path:
d:\cygdrive\d\x\git\myproject\.git\commit_editmsg
note the addition of "\cygdrive\d"
How can I make git pass the windows path (rather than the cygwin/unix path) to my editor?
The command to do this is git config --global core. editor "nano" . You can change the highlighted section with your editor of choice!
If you want to save your changes and quit, press Esc then type :wq and hit Enter or ↵ or on Macs, Return .
cygwin has a utility called cygpath
which can be used to convert between cygwin and native Windows file paths. For instance:
$ cygpath --windows /cygdrive/d/X/git/myproject
D:\X\git\myproject
We're going to create a script which uses this utility to convert the path before passing it to your editor. We'll use emacs as an example, assuming it is installed at C:\emacs
. Create a file called ~/bin/git-editor.sh
:
#!/bin/sh
/cygdrive/c/emacs/bin/emacsclientw.exe $(cygpath --windows "${1}")
(since this is Windows, we don't need to set the executable flag on this file)
Now, set your git editor to point to this script:
$ git config --global core.editor "~/bin/git-editor.sh"
#!/bin/dash -e
if [ "$1" ]
then k=$(cygpath -w "$1")
elif [ "$#" != 0 ]
then k=
fi
Notepad2 ${k+"$k"}
If no path, pass no path
If path is empty, pass empty path
If path is not empty, convert to Windows format.
Then I set these variables:
export EDITOR=notepad2.sh
export GIT_EDITOR='dash /usr/local/bin/notepad2.sh'
EDITOR allows script to work with Git
GIT_EDITOR allows script to work with Hub commands
Source
I had the same problem. Cygwin git would not pass the correct path to sublime 3 (It would not include the cygwin64 folder) I created the git-editor.sh folder, this is what I put in it:
#!/bin/sh
/cygdrive/c/Program\ Files/Sublime\ Text\ 3/subl.exe $(cygpath --windows "${1}") -w
Then made this .sh file my core.editor
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With