Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make commit diff appear in commit message while I'm editing it (with Vim)?

Tags:

git

vim

My biggest bottleneck in vim is the moment when I need to write a commit. Often, i do not remember the diff. First I write "git diff". Then I write "git commit" but, ... "Hey! I do not remember ...". Thus, I need to stop to write commit message, then I come back and run diff message. Sometimes I work with two windows: on the left I run "git diff". On the right I run "git commit". This allow me to write a commit message complete, while I can watch the diff of each file, ... and so on.

Can someone help me to improve this moment in vim workflow?

like image 825
sensorario Avatar asked Oct 20 '14 00:10

sensorario


2 Answers

Use git commit -v to see the diff in vim while committing.

-v, --verbose
    Show unified diff between the HEAD commit and what would be
    committed at the bottom of the commit message template. Note
    that this diff output doesn't have its lines prefixed with #.
like image 164
FDinoff Avatar answered Nov 09 '22 22:11

FDinoff


The ftplugin/gitcommit.vim that ships with Vim has a :DiffGitCached command, which opens the diff in a split scratch buffer. I've assigned a quick mapping to it (in ~/.vim/after/ftplugin/gitcommit.vim):

nnoremap <LocalLeader><LocalLeader> :DiffGitCached<CR>
like image 36
Ingo Karkat Avatar answered Nov 09 '22 22:11

Ingo Karkat