Search code examples
gitvimgerritvim-fugitive

How to edit specific version of file in fugitive


Some content has been moved from a .c file to a .h file in my repository and I want to compare them to ensure that the new header is correct. This is for a Gerrit review and I am assuming there's no simple way to do this using the Gerrit toolchain.

I am trying to edit the .h file in one window and the old version of the .c file. When I issue the Gedit FETCH_HEAD:path/from/root/to/file.c always gives the following error: E492: Not an editor command: Gedit FETCH_HEAD:path/from/root/to/file.c. I've also tried the command using the hash.

What am I missing?


Solution

  • Fugitive commands are only available when the current buffer is controlled by git or when vim first starts up is in a git directory.

    Just open any file in the git repository before issuing your :Gedit command.

    :e path/from/root/to/file.c
    :Gedit FETCH_HEAD:%
    

    Note: Using % to represent the current file. See :h c_%