Review Last Commit With Vim and Fugitive
When working with git, it's often useful to review all changes that you have made in last commit before push them to origin.
To see difference between current HEAD and previous commit, one can use:
git diff HEAD~
Vim have awesome git wrapper - fugitive, written by Tim Pope, author of many other great plugins.
Reviewing last commit in fugitive can be a little tricky:
:Gtabedit HEAD^{}
This command open new tab with all changes from last commit. You can map it like any other command.
I wrote a small function that add additional binding - q
for close fugitive
buffer:
function! ReviewLastCommit()
if exists('b:git_dir')
Gtabedit HEAD^{}
nnoremap <buffer> <silent> q :<C-U>bdelete<CR>
else
echo 'No git a git repository:' expand('%:p')
endif
endfunction
Example mapping:
map <silent> <F10> :call ReviewLastCommit()<CR>