
我已經完成了 git-diff 來產生補丁檔案:
cd
git diff --no-prefix ~/.vim/bundle/vim-latex-suite/ftplugin/latex-suite/compiler.vim ~/compiler.vim > ~/vimlatex.patch
產生的補丁是
diff --git home/rudra/.vim/bundle/vim-latex-suite/ftplugin/latex-suite/compiler.vim home/rudra/compiler.vim
index 65cd33a..abfcff7 100644
--- home/rudra/.vim/bundle/vim-latex-suite/ftplugin/latex-suite/compiler.vim
+++ home/rudra/compiler.vim
@@ -434,7 +434,8 @@ function! Tex_ForwardSearchLaTeX()
else
" We must be using a generic UNIX viewer
" syntax is: viewer TARGET_FILE LINE_NUMBER SOURCE_FILE
-
+ let mainfnameRelative = fnameescape(fnamemodify(Tex_GetMainFileName(), ':p:.:r'))
+ let target_file = mainfnameRelative . "." . s:target
let execString .= join([viewer, target_file, linenr, sourcefile])
endif
我想應用這個補丁/home/rudra/.vim/bundle/vim-latex-suite/ftplugin/latex-suite/compiler.vim
但是當我嘗試應用補丁時,它給出了:
patch -p0 < vimlatex.patch
can't find file to patch at input line 5
Perhaps you used the wrong -p or --strip option?
The text leading up to this was:
--------------------------
|diff --git home/rudra/.vim/bundle/vim-latex-suite/ftplugin/latex-suite/compiler.vim home/rudra/compiler.vim
|index 65cd33a..abfcff7 100644
|--- home/rudra/.vim/bundle/vim-latex-suite/ftplugin/latex-suite/compiler.vim
|+++ home/rudra/compiler.vim
--------------------------
File to patch: /home/rudra/.vim/bundle/vim-latex-suite/ftplugin/latex-suite/compiler.vim
patching file /home/rudra/.vim/bundle/vim-latex-suite/ftplugin/latex-suite/compiler.vim
問題是,雖然它工作正常,但我希望它了解應該修補哪個文件,而不詢問我要修補的文件:
我怎樣才能做到這一點?
答案1
預設情況下,patch
從目標檔案中刪除路徑,因此您可以使用以下命令套用補丁
patch < vimlatex.patch
compiler.vim
(假設目前目錄中有一個檔案)。
指定-p0
指示它使用所有目標路徑,因此它期望home/rudra/compiler.vim
從當前目錄開始找到一個名為的檔案。對此的解釋是,用於創建補丁的命令在diff
運行之前已被轉換;真正用於創建補丁的命令被記錄為補丁的第一行(基本上,~
變成/home/rudra
,並且前導/
被刪除):
diff --git home/rudra/.vim/bundle/vim-latex-suite/ftplugin/latex-suite/compiler.vim home/rudra/compiler.vim
因此,patch -p0
默認情況下期望找到一個匹配的文件home/rudra/compiler.vim
(目標文件),如上所述。
我認為沒有可靠的方法來產生您想要的補丁,因為patch
明確忽略了絕對路徑。我建議只使用普通的diff
相對路徑:
cd
diff -u .vim/bundle/vim-latex-suite/ftplugin/latex-suite/compiler.vim compiler.vim > vimlatex.patch
並將補丁套用到適當的目錄中。