在我编辑它时(如果使用Vim),如何在提交消息中显示提交差异?

时间:2014-10-20 00:45:45

标签: git vim

我在vim中遇到的最大瓶颈是我需要编写提交的那一刻。通常,我不记得差异。首先我写“git diff”。然后我写“git commit”但是,......“嘿!我不记得了......”。因此,我需要停止写提交消息,然后我回来并运行diff消息。有时我使用两个窗口:在左边我运行“git diff”。在右边我运行“git commit”。这允许我写一个提交消息完成,而我可以观察每个文件的差异,......等等。

有人可以帮助我在vim工作流程中改善这一时刻吗?

4 个答案:

答案 0 :(得分:12)

使用git commit -v在提交时查看vim中的差异。

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

答案 1 :(得分:2)

Vim附带的ftplugin/gitcommit.vim有一个:DiffGitCached命令,可以在分割暂存缓冲区中打开差异。我已经为其分配了快速映射(在~/.vim/after/ftplugin/gitcommit.vim中):

nnoremap <LocalLeader><LocalLeader> :DiffGitCached<CR>

答案 2 :(得分:1)

您可以使用git commit -p查看提交之前所做的所有更改。见man git commit

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

编辑:有关更好的方法,请参阅@ Fdinoff对您的问题的评论。

答案 3 :(得分:0)

对于那些使用fugitive使用:Gcommit -v或在cvc窗口中使用:Gstatus映射的人。

有关详细信息,请参阅以下内容:

:h :Gcommit
:h :Gstatus
相关问题