Cygwin git going the wrong way to my editor for commit messages

I use git under cygwin, but it does not pass the correct path to my editor for commit messages.

I work 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 my editor to enter a message), my editor tries to write the 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 path to Windows (and not the cygwin / unix path) to my editor?

+4
source share
3 answers

Cygwin has a utility called cygpath that 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 are going to create a script that uses this utility to convert the path before passing it to your editor. We will use emacs as an example, assuming it is installed in 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 do not need to set the executable flag in this file)

Now set the git editor to the value for this script:

 $ git config --global core.editor "~/bin/git-editor.sh" 
+5
source
 #!/bin/dash -e if [ "$1" ] then k=$(cygpath -w "$1") elif [ "$#" != 0 ] then k= fi Notepad2 ${k+"$k"} 
  • If there is no way, do not miss the way

  • If the path is empty, skip the empty path

  • If the path is not empty, go to the 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

+2
source

I had the same problem. Cygwin git will not pass the correct path to sublime 3 (it will not contain the cygwin64 folder). I created the git -editor.sh folder, here is what I added to it:

 #!/bin/sh /cygdrive/c/Program\ Files/Sublime\ Text\ 3/subl.exe $(cygpath --windows "${1}") -w 

Then made this .sh file my core.editor

0
source

All Articles