How do I view the git commit history for the current file in vim-fugitive?
Answer
:0Gclog
Explanation
vim-fugitive's :Gclog command loads the git log into the quickfix list, but when prefixed with the range 0 it restricts the history to only the commits that touched the current file. This lets you navigate backward through every revision of a file without leaving Vim.
How it works
:Gclogloads all commits into the quickfix list- The
0range (:0Gclog) limits the log to commits that changed the current file — equivalent togit log -- % - Each quickfix entry is a commit; pressing
<CR>opens that historical version of the file in a fugitive buffer - Use
:cnext/:cprev(or:cn/:cp) to walk forward and backward through commits - From a historical buffer,
:Gdiffcompares it to the working copy
Example
:0Gclog " load file history into quickfix
:copen " open quickfix window to browse commits
:cnext " jump to the next (older) commit
:cprev " jump back to the newer commit
Press <CR> on a quickfix entry to open that snapshot. The buffer title shows the commit SHA and filename.
Tips
- Combine with a range to inspect history for specific lines:
:'<,'>Gclogloads only commits that touched the visually selected lines - Pass extra git-log flags after the command:
:0Gclog --since=2.weeks.ago :Glloguses the location list instead of quickfix, so each file gets its own list- After opening a historical version,
:Greadreplaces the working buffer with that revision