vimtricks.wiki Concise Vim tricks, one at a time.

How do I diff the current file against a specific git commit using vim-fugitive?

Answer

:Gdiffsplit HEAD~1

Explanation

vim-fugitive's :Gdiffsplit opens a vertical split showing the current file diff against any git revision — not just HEAD. Passing a commit reference like HEAD~1, a branch name, or a full SHA gives you an instant side-by-side diff without leaving Vim. This is much faster than running git diff in a terminal and trying to correlate line numbers.

How it works

  • :Gdiffsplit — diff working tree file against the index (staged version)
  • :Gdiffsplit HEAD — diff working tree file against the last commit
  • :Gdiffsplit HEAD~1 — diff against the commit before HEAD (the second-to-last commit)
  • :Gdiffsplit HEAD~3 — diff against 3 commits ago
  • :Gdiffsplit main — diff against the tip of the main branch
  • :Gdiffsplit abc1234 — diff against a specific commit SHA

The split opens in Vimdiff mode. Use ]c and [c to jump between diff hunks, and :diffoff to exit diff mode.

Example

You've been working on utils.py and want to see what changed since yesterday's last commit:

:Gdiffsplit HEAD~1

A vertical split opens with the old version on the left and your current working tree on the right, with changed lines highlighted. Press ]c to jump to the first changed hunk.

Tips

  • Use :Gvdiffsplit for an explicit vertical split (:Gdiffsplit respects diffopt)
  • :Gdiffsplit! opens a 3-way merge diff (base, ours, theirs) during a merge conflict
  • Press q or :q on the fugitive buffer to close the split and exit diff mode
  • Combine with :diffget / :diffput to cherry-pick specific hunks between revisions

Next

How do I see a summary of all previous quickfix lists from my current session and navigate between them?