Windows 版 Git 中的 vimdiff 给出 E810 和 E97

Windows 版 Git 中的 vimdiff 给出 E810 和 E97

我正在使用 Windows 版 Git(git 版本 2.5.3.windows.1),并且已将 vimdiff 设置为我的合并工具。git mergetool从 git bash 运行会导致以下错误:

E810: Cannot read or write temp files
E97: Cannot create diffs
Press ENTER or type command to continue

现在,我知道你在想什么,这是无法在 Windows 7 上运行 vimdiff-7-4,但我尝试了解决方案,但它不起作用(或者我遗漏了什么)。另外,我没有安装 vim,它是随 Windows 版 Git 一起提供的,我认为它可能有所不同(不是 100% 确定)。

这是我的~/.vimrc文件(在底部你会看到我添加了MyDiff()set diffexpr=MyDiff(),也许我做错了?)(此外,值得一提的是,这个“顶部”不是来自 Windows 版 Git 的“示例”vimrc,而是来自 Cygwin 的,但我怀疑这并不重要。):

" An example for a vimrc file.
"
" Maintainer:   Bram Moolenaar <[email protected]>
" Last change:  2014 Nov 05
"
" To use it, copy it to
"     for Unix and OS/2:  ~/.vimrc
"         for Amiga:  s:.vimrc
"  for MS-DOS and Win32:  $VIM\_vimrc
"       for OpenVMS:  sys$login:.vimrc

" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
  finish
endif

" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible

" allow backspacing over everything in insert mode
set backspace=indent,eol,start

if has("vms")
  set nobackup      " do not keep a backup file, use versions instead
else
  set backup        " keep a backup file (restore to previous version)
  set undofile      " keep an undo file (undo changes after closing)
endif
set history=50      " keep 50 lines of command line history
set ruler       " show the cursor position all the time
set showcmd     " display incomplete commands
set incsearch       " do incremental searching

" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")

" Don't use Ex mode, use Q for formatting
map Q gq

" CTRL-U in insert mode deletes a lot.  Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>

" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
  set mouse=a
endif

" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
  syntax on
  set hlsearch
endif

" Only do this part when compiled with support for autocommands.
if has("autocmd")

  " Enable file type detection.
  " Use the default filetype settings, so that mail gets 'tw' set to 72,
  " 'cindent' is on in C files, etc.
  " Also load indent files, to automatically do language-dependent indenting.
  filetype plugin indent on

  " Put these in an autocmd group, so that we can delete them easily.
  augroup vimrcEx
  au!

  " For all text files set 'textwidth' to 78 characters.
  autocmd FileType text setlocal textwidth=78

  " When editing a file, always jump to the last known cursor position.
  " Don't do it when the position is invalid or when inside an event handler
  " (happens when dropping a file on gvim).
  " Also don't do it when the mark is in the first line, that is the default
  " position when opening a file.
  autocmd BufReadPost *
    \ if line("'\"") > 1 && line("'\"") <= line("$") |
    \   exe "normal! g`\"" |
    \ endif

  augroup END

else

  set autoindent        " always set autoindenting on

endif " has("autocmd")

" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
  command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
          \ | wincmd p | diffthis
endif

if has('langmap') && exists('+langnoremap')
  " Prevent that the langmap option applies to characters that result from a
  " mapping.  If unset (default), this may break plugins (but it's backward
  " compatible).
  set langnoremap
endif

" Set tab width stuff
set tabstop=4 softtabstop=0 noexpandtab shiftwidth=4

" Assign diff tool to MyDiff() method
set diffexpr=MyDiff()

" Used for diff
function MyDiff()
  let opt = '-a --binary '
  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  let arg1 = v:fname_in
  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
  let arg2 = v:fname_new
  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  let arg3 = v:fname_out
  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
  if $VIMRUNTIME =~ ' '
    if &sh =~ '\<cmd'
      if empty(&shellxquote)
        let l:shxq_sav = ''
        set shellxquote&
      endif
      let cmd = '"' . $VIMRUNTIME . '\diff"'
    else
      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
    endif
  else
    let cmd = $VIMRUNTIME . '\diff'
  endif
  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
  if exists('l:shxq_sav')
    let &shellxquote=l:shxq_sav
  endif
endfunction

为了彻底起见,:version给出如下内容:

VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Sep 16 2015 08:44:57)
Included patches: 1-872
Compiled by <[email protected]>
Huge version without GUI.  Features included (+) or not (-):
+acl             +cmdline_compl   +diff            +find_in_path    +keymap          +modify_fname    +mouse_xterm     +profile         -sniff           +termresponse    +vreplace        -xterm_save
+arabic          +cmdline_hist    +digraphs        +float           +langmap         +mouse           +multi_byte      +python/dyn      +startuptime     +textobjects     +wildignore      -xpm
+autocmd         +cmdline_info    -dnd             +folding         +libcall         -mouseshape      +multi_lang      +python3/dyn     +statusline      +title           +wildmenu
-balloon_eval    +comments        -ebcdic          -footer          +linebreak       +mouse_dec       -mzscheme        +quickfix        -sun_workshop    -toolbar         +windows
-browse          +conceal         +emacs_tags      +fork()          +lispindent      -mouse_gpm       +netbeans_intg   +reltime         +syntax          +user_commands   +writebackup
++builtin_terms  +cryptv          +eval            +gettext         +listcmds        -mouse_jsbterm   +path_extra      +rightleft       +tag_binary      +vertsplit       -X11
+byte_offset     +cscope          +ex_extra        -hangul_input    +localmap        +mouse_netterm   +perl/dyn        +ruby/dyn        +tag_old_static  +virtualedit     -xfontset
+cindent         +cursorbind      +extra_search    +iconv           -lua             +mouse_sgr       +persistent_undo +scrollbind      -tag_any_white   +visual          -xim
-clientserver    +cursorshape     +farsi           +insert_expand   +menu            -mouse_sysmouse  +postscript      +signs           -tcl             +visualextra     -xsmp
+clipboard       +dialog_con      +file_in_path    +jumplist        +mksession       +mouse_urxvt     +printer         +smartindent     +terminfo        +viminfo         -xterm_clipboard
   system vimrc file: "/etc/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
  fall-back for $VIM: "/etc"
 f-b for $VIMRUNTIME: "/usr/share/vim/vim74"
Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H   -D_FORTIFY_SOURCE=2 -I/usr/include/ncursesw  -march=x86-64 -mtune=generic -O2 -pipe -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc   -L. -pipe -fstack-protector -pipe -Wl,--as-needed -o vim.exe        -lm    -lncursesw -liconv -lintl   -pipe -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,--enable-auto-image-base -fstack-protector-strong  -L/usr/lib/perl5/core_perl/CORE -lperl -lpthread -ldl -lcrypt

答案1

我误解了它的用途MyDiff(),我以为它是为了在 Windows 上使用 vim一般来说,它是专门用于在 Windows 上的 cmd 中使用 vim 的——但我是通过 git bash 使用它的。解决方案是删除所有这些,如下所示这里运行这个:

MSYS_NO_PATHCONV=1 git mergetool

或者我可以设置MSYS_NO_PATHCONV=1在我的.bash_profile.bashrc

# Set MSYS to not convert paths
export MSYS_NO_PATHCONV=1

相关内容