Skip to content

Latest commit

 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

history-git-diff.nvim

A simple Neovim plugin that provides a convenient API over git's native diff functionality for viewing file history.


⚠️ Important Disclaimer

This is a hobby project for personal use - NOT production-ready!

  • Experimental: Built for fun and personal workflow optimization
  • Limited testing: Only tested on macOS with basic git repositories
  • No warranty: Use at your own risk
  • Performance: May be slow on files with extensive history

Feel free to use, modify, or learn from it, but don't expect production quality!


What This Is

This plugin is essentially a convenient wrapper around git's native diff functionality. It provides a simple interface to:

  • Browse git commit history for the current file
  • Select any commit to diff against
  • View the differences in Neovim's built-in diff mode

Think of it as running git log <file> and git show <commit>:<file> with a nice UI wrapper.

Screenshots

Interactive Commit Selection

The plugin provides a floating popup window to browse and select commits from your file's history:

Commit Selection Popup

Diff View

Once you select a commit, the plugin opens Neovim's native diff mode to compare the current file with the historical version:

Git Diff View

Alternative (Better) Tools

If you're looking for more feature-rich git integration, consider these excellent alternatives:

  • gitsigns.nvim - Comprehensive git decorations and hunk management with :Gitsigns diffthis <revision>
  • diffview.nvim - Advanced diff viewer with file history browser (:DiffviewFileHistory)
  • vim-fugitive - The definitive git plugin for Vim/Neovim with :Glog and :0Gclog
  • neogit - Magit clone for Neovim with comprehensive git interface
  • vim-gitgutter - Git diff markers in sign column with preview capabilities

These plugins offer more features, better performance, and are actively maintained by the community.

Features

  • View git commit history for the current file
  • Interactive popup window with commit selection
  • Diff current file (including unsaved changes) against any historical version
  • Terminal color scheme support (cterm colors)
  • Configurable pane layout
  • Simple and focused - does one thing

Requirements

  • Neovim >= 0.7.0
  • Git installed and accessible in PATH
  • File must be in a git repository and tracked by git

Installation

Using lazy.nvim

{
  'morass/history-git-diff.nvim',
  config = function()
    require('history-git-diff').setup({
      -- Configuration options (see below)
    })
  end,
}

Using vim-plug

Plug 'morass/history-git-diff.nvim'

Then in your init.vim:

lua require('history-git-diff').setup()
use {
  'morass/history-git-diff.nvim',
  config = function()
    require('history-git-diff').setup()
  end
}

Manual Installation

Clone the repository:

git clone https://github.com/morass/history-git-diff.nvim ~/.local/share/nvim/site/pack/plugins/start/history-git-diff.nvim

Then setup in lua:

require('history-git-diff').setup()

Configuration

Lua Configuration

require('history-git-diff').setup({
  swap_panes = false,  -- Set to true to swap pane positions
})

Vimscript Configuration

If you prefer to configure from Vimscript (e.g., in your init.vim):

" Set configuration before calling setup
let g:history_git_diff_config = {'swap_panes': v:true}

" Then call setup
lua require('history-git-diff').setup(vim.g.history_git_diff_config)

Or inline:

" Swap panes directly in setup call
lua require('history-git-diff').setup({ swap_panes = true })

Options

  • swap_panes (boolean, default: false)
    • false: Current file on LEFT (editable), Historical version on RIGHT (read-only)
    • true: Historical version on LEFT (read-only), Current file on RIGHT (editable)

Usage

  1. Open any file that's tracked by git
  2. Run :DiffHistory command
  3. Navigate commits with j/k
  4. Press Enter to view diff with selected commit
  5. Press ESC or q to cancel

Popup Window Controls

  • j / k - Navigate through commits
  • Enter - Open diff view with selected commit
  • ESC / q - Close popup and cancel

Diff View

The diff view opens in a new tab with:

  • Default layout (swap_panes = false):
    • Left pane: Current file (editable, includes unsaved changes)
    • Right pane: Historical version (read-only)
  • Swapped layout (swap_panes = true):
    • Left pane: Historical version (read-only)
    • Right pane: Current file (editable, includes unsaved changes)

Close the tab when done to return to your work.

How It Works

Under the hood, this plugin simply:

  1. Runs git log to get commit history for current file
  2. Shows commits in a floating window
  3. When selected, runs git show <commit>:<file> to get historical version
  4. Opens Neovim's diff mode to compare versions

It's essentially a UI wrapper around basic git commands.

Limitations

  • Only shows commits from current branch (by design)
  • Limited to 100 most recent commits
  • Requires file to be tracked by git
  • No support for renamed/moved files history
  • Simple terminal colors only (no fancy theming)

Color Scheme

Uses terminal colors (cterm) for consistency:

  • Blue: Commit hashes
  • Gray: Help text and dates
  • Red: Cancel option
  • White: Commit messages

Troubleshooting

"Not in a git repository": Make sure you're in a git repo (git status should work)

"File is not tracked by git": The file needs to be added to git (git add <file>)

No commits found: The file might be newly added with no commit history yet

Colors look wrong: The plugin uses terminal colors - appearance depends on your terminal theme

License

Do whatever you want with it. No warranties, no support, just a fun little tool.


Remember: This is a hobby project. It might break, it might have bugs, but it gets the job done (usually).

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages