7

Show Git Diff When Doing Git Commit

 3 years ago
source link: https://jdhao.github.io/2021/07/24/git_show_diff_when_commiting/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Show Git Diff When Doing Git Commit

2021-07-24252 words 2 mins read 578 times read

I saw on YouTube a video made by TJ DeVries on how to contribute to the neovim project. There is a scene where he commit via git commit, and whoa, a Neovim instance appeared with three split, with top left the commit message area, top right the git-status area, and on the right the git-diff info, which is really cool.

A little background, the default git commit only shows status info without the diff info. For commit related to changes in several files, it is difficult to remember all the diffs and summarize them in the commit message.

I searched a bit and figured out how to do it in Neovim.

Native git options

First, make sure that commit message editor is set to Vim or Neovim:

git config --global core.editor nvim

We can add --verbose/-v option when commiting to show the diff info:

git commit -v

Better, to set it permanently (for Git version above 2.9.0):

git config --global commit.verbose true

With the above config, the diff info will be shown below the status info. For short diffs, it is acceptable, while for longer diffs, it is still not easy to check.

Using a plugin

committia.vim is a plugin that re-arrange the commit window for easier writing of commit messages. When you run git commit, it will automatically show a three-split window like the following:

References

Author jdhao

LastMod 2021-07-24

License CC BY-NC-ND 4.0

Reward
Delete Keys Matching A Pattern with py-redis-cluster

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK