Cygwin git将错误的路径传递给我的编辑器以提交消息 [英] Cygwin git passing wrong path to my editor for commit messages

查看:51
本文介绍了Cygwin git将错误的路径传递给我的编辑器以提交消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在cygwin下使用git,但是没有将正确的路径传递给我的编辑器来提交消息.

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

在cygwin终端中,该路径显示为:

in the cygwin terminal it shows this path as:

/cygdrive/d/X/git/myproject

当我提交时没有-m标志(以便打开编辑器供我输入消息)时,编辑器将尝试将文件写入错误的路径:

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

请注意添加了"\ cygdrive \ d"

如何让git将Windows路径(而不是cygwin/unix路径)传递给我的编辑器?

How can I make git pass the windows path (rather than the cygwin/unix path) to my editor?

推荐答案

cygwin有一个名为 cygpath 的实用程序,可用于在cygwin和本机Windows文件路径之间进行转换.例如:

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

我们将创建一个脚本,该脚本使用此实用程序在将路径传递给您的编辑器之前对其进行转换.我们以emacs为例,假设它安装在 C:\ emacs 上.创建一个名为〜/bin/git-editor.sh 的文件:

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}")

(因为这是Windows,所以我们不需要在此文件上设置可执行标志)

(since this is Windows, we don't need to set the executable flag on this file)

现在,将您的git编辑器设置为指向此脚本:

Now, set your git editor to point to this script:

$ git config --global core.editor "~/bin/git-editor.sh"

这篇关于Cygwin git将错误的路径传递给我的编辑器以提交消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆