sensorario
sensorario

Reputation: 21620

How do I make commit diff appear in commit message while I'm editing it (with 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?

Upvotes: 9

Views: 462

Answers (4)

Peter Rincker
Peter Rincker

Reputation: 45117

For those using fugitive use :Gcommit -v or use cvc mapping in the :Gstatus window.

See the following for more information:

:h :Gcommit
:h :Gstatus

Upvotes: 0

Ingo Karkat
Ingo Karkat

Reputation: 172598

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>

Upvotes: 3

FDinoff
FDinoff

Reputation: 31429

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 #.

Upvotes: 18

Brett Y
Brett Y

Reputation: 7678

You could use git commit -p to see all the changes being made before committing them. See man git commit

-p, --patch
    Use the interactive patch selection interface to chose which changes to commit.
    See git-add(1) for details.

Edit: See @Fdinoff's comment on your question for a better way.

Upvotes: 1

Related Questions