使用 gvim for windows 和 msys git 1.7.0.2 使用 fugitive.vim 的 :GDiff 命令时出错
当我在 Windows 上时,我一直使用 git 和 fugitive.vim 来管理代码。但是,我遇到了问题。根据 文档, :GDiff 命令应该是一个 diff 窗口并允许我仅暂存文件的一部分。但是,当我在包含更改的文件中发出命令时,我收到以下错误消息:
这是 Windows 的问题吗?维姆?逃亡者? msysgit?文件权限?有人知道吗?
I've been using git along with fugitive.vim to manage code when I'm on windows. However, I've run into a problem. According to the documentation, the :GDiff command should a diff window and allow me to stage only parts of a file. However, when I issue the command in a file with changes, I get the following error message:
Is this a problem with windows? vim? fugitive? msysgit? file permissions? Anybody know?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我遇到了同样的问题 - 这是我解决它的方法。
默认情况下,Vim 会尝试将交换文件存储在原始文件旁边。 Fugitive 创建一个不对应于任何真实文件路径的缓冲区,因此 Vim 在尝试创建交换文件时会失败。解决方案是确保 Vim 有一个可以写入的路径。
我是这样解决这个问题的:
这是 GitHub 上的原始问题:
https://github.com/tpope/vim-fugitive/issues/9
编辑:
正如下面fow指出的那样,最好使用如下所示的内容:
Vim 应该使用它可以使用的第一个路径。
I had the same problem - here's how I fixed it.
By default, Vim will try to store swap files beside the original. Fugitive creates a buffer that does not correspond to any real file path, so Vim barfs when it tries to create the swap file. The solution is to make sure that Vim has a path it can write to.
Here's how I fixed this:
Here's the original issue on GitHub:
https://github.com/tpope/vim-fugitive/issues/9
EDIT:
As fow points out below, it's probably better to use something like the following:
Vim should use the first path it can.
我没有 Windows 计算机,但我能够在 Mac OS X 10.6 系统上重现并隔离此问题。
创建
C:\TMP
或C:\TEMP
(:help 'directory'
表示两者都在 Windows 版本的 Vim 上的directory
选项的默认值中),或者将现有目录添加到directory
选项的值中。我在我的主目录下使用 Vim 特定的临时目录(同样,这里没有 Windows)并添加两个尾部斜杠 (
~/tmp/.vim-swaps//
)。这种设置集中交换文件,但根据正在编辑的文件的目录为它们提供唯一的名称。请参阅:help :swapname
以及:help 中的“如果目录以两个路径分隔符结尾”位“目录”
。使用
^=
前置 1 您的目录(以便始终使用它(如果存在):或者,使用
+=
附加您的目录目录(以便仅在存在且不存在其他适用的directory
条目时使用它):Charles 的回答表明
$TMP
(参考环境变量)对于 Windows 可能是一个不错的值:根本原因与
directory
选项的默认值与:Gdiff
索引的路径名相结合“伪”文件。:Gdiff
视图索引端的缓冲区使用特殊的路径名,如下所示fugitive:///path/to/repository/.git//0/path/to/file /under/repository
(逃逸捕获对所谓缓冲区的读取和写入,并通过调用 Git“管道”命令将它们重定向到索引)。目录
中的第一个条目通常是.
。这意味着 Vim 将尝试将交换文件放在与编辑的文件相同的目录中(即foo/bar.txt
将尝试使用foo/.bar.swp
) 。如果无法创建此首选交换文件,则将尝试directory
中的后续条目。将
.
作为第一个目录
,为fugitive:///path/to/repository/.git//0/path/to/file 的首选交换文件/under/repository
将是fugitive:///path/to/repository/.git//0/path/to/file/under/.repository.swp
。该路径名的前导部分(fugitive:
、path
、to
等)可能不存在,因此 Vim 将继续执行目录
中的下一个条目。如果没有其他目录
条目可用于创建交换文件(例如它们不存在),那么您会收到错误E302。我能够使用
set directory=.,~/no-such-dir,/var/no-such-dir,/no-such-dir
在 Unix-y 系统上重现您的问题(即采用默认的 Unix 值并将出现的tmp
更改为no-such-dir
)。实际上,“no-such-dir”目录都不存在。当我使用:Gdiff
时,我遇到了同样的错误。1
:help :set^=
只表示“add”,但代码显示set listopt^=...
的前置方式类似于set listopt+=...
的附加方式(正如后者记录的那样) 。两者都应该根据需要自动插入逗号(尽管这方面可能存在错误)。I do not have a Windows machine, but I was able to reproduce and isolate this problem on a Mac OS X 10.6 system.
Either create
C:\TMP
orC:\TEMP
(:help 'directory'
says both are in the default value of thedirectory
option on Windows builds of Vim), or add an existing directory to the value of thedirectory
option.I use a Vim-specific temporary directory under my home directory (again, no Windows here) and add two trailing slashes (
~/tmp/.vim-swaps//
). This kind of setting centralizes the swap files but gives them unique names based on the directories of the files being edited. See “Advantages” and “Disadvantages” in:help :swapname
as well as the“if a directory ends in two path separators” bit in
:help 'directory'
.Use
^=
to prepend1 your directory (so that it is always used, if it exists):Or, use
+=
to append your directory (so that it is only used if it exists and no other applicabledirectory
entries exist):Charles’ answer suggests that
$TMP
(a reference to an environment variable) might be a good value for Windows:The root cause is related to the default value of the
directory
option combined with the pathname of:Gdiff
’s index “pseudo” file.The buffer for the index side of a
:Gdiff
view uses a special pathname that looks likefugitive:///path/to/repository/.git//0/path/to/file/under/repository
(fugitive captures reads and writes to so named buffers and redirects them to the index by invoking Git “plumbing” commands).The first entry in
directory
is usually.
. This means that Vim will try to put the swapfile in the same directory as the edited file (i.e.foo/bar.txt
will try to usefoo/.bar.swp
). If this preferred swapfile can not be created, then subsequent entries fromdirectory
will be tried.With
.
as the firstdirectory
, the preferred swapfile forfugitive:///path/to/repository/.git//0/path/to/file/under/repository
will befugitive:///path/to/repository/.git//0/path/to/file/under/.repository.swp
. The leading components of this pathname (fugitive:
,path
,to
, etc.) probably do not exist, so Vim will go on to the next entry fromdirectory
. If none of the otherdirectory
entries are usable for creating swap files (e.g. they do not exist), then you get error E302.I was able to reproduce your problem on a Unix-y system by using
set directory=.,~/no-such-dir,/var/no-such-dir,/no-such-dir
(i.e. taking the default Unix value and changing occurrences oftmp
tono-such-dir
). None of the “no-such-dir” directories actually existed. I got the same error when I use:Gdiff
.1
:help :set^=
only says “add”, but the code shows thatset listopt^=…
prepends similar to howset listopt+=…
appends (as the latter is documented to do). Both should automatically insert commas as needed (though there may have been bugs in this area).这可能与 msysgit 的 问题 428 有关在我的回答中提到。
尝试按照我之前的回答中所述修补
cmd/git.cmd
,看看是否有帮助。除此之外,还有两个选择:
注意:第三个选项,尝试降级 Git,再次排除与该工具的任何链接。
That may be related to the issue 428 of msysgit mentioned in my SO answer.
Try patching the
cmd/git.cmd
as I describe in my previous answer and see if this help.Baring that, 2 options remains:
Note: third option, trying to downgrade Git, again to rule out any link with that tool.
顺便说一句,当我尝试 :gdiff 未保存的文件时,我遇到了同样的错误 - 当我保存它时 (:w) 它有效!
BTW same error I got, when I tried to :gdiff unsaved file - when i saved it (:w) it works!