2017-08-25 123 views
0

所以我一直在使用vim fugitive插件,我发现Glogcnext功能很棒,看看文件是如何随时间变化的。使用cnext提交结账文件

我想使用cnext命令从我提交的提交中检出文件。是否有可能这样做?

+2

打开修订版,试试'Gwrite',如果这是你想要的,请报告 – Kent

+0

@当它打开'HEAD'时。 – sitilge

+0

如何询问插件的作者? – romainl

回答

1

如果插件没有提供相应的命令,希望这个功能有帮助。

当在文件提交日志的quickfix窗口中按gc

autocmd FileType qf nnoremap<buffer> gc :call GitCheckoutFile()<cr> 

function! GitCheckoutFile() 
    let l = getline('.') 
    if match(l, '\vfugitive:\\\\') != -1 
     let path = substitute(l, '\v(fugitive:\\\\)|(\|.*)', '', 'g') 

     let commit_id = matchstr(path, '\v.git\\\\\zs\w*\ze\\') 
     let commit_info = matchstr(path, '\v.git\\\\\w*\\') 
     let file = substitute(path, escape(commit_info, '\'), '', 'g') 

     execute 'Git checkout '.commit_id.' -- '.file 
    endif 
endfunction 
+0

我认为利用逃犯会更容易。通过'matchstr(fugitive#buffer()。rev(),'\ x \ {40}')'和文件路径通过'fugitive @ buffer()。path()' –

+0

获得一个缓冲区的修订版本,杠杆逃犯。 – leaf

1

最简单的方法是简单地复制/抽出当前使用的缓冲区,然后用最近抽取的副本替换当前版本。

:%y|Gedit|%d_|put|0d_|w 

但是,如果你宁愿做这个通过:Gread命令,你可以做到以下几点:

:execute "Gedit|Gread! show " . matchstr(fugitive#buffer().rev(), '\x\{40}') . ":". fugitive#buffer().path() 

您可能需要包装的这些高达一成的映射或命令,如果你经常这样。

+0

这是一个更简单的解决方案。 “shellescape”似乎对我的案例的最终命令产生了错误。和错字:第二个'fugtive'。 – leaf

+0

@叶你是正确的。我已更新该帖子 –