3

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?

Stephen Rasku
  • 2,554
  • 7
  • 29
  • 51
  • 1
    Fugitive commands are only available when the current buffer is controlled by git or when vim is invoked on startup in a git directory. Are you editing a git controlled file before invoking the `:Gedit` command? – Peter Rincker Aug 02 '16 at 21:51
  • Apparently not. I keep forgetting I have to do that. If you want to create an answer that essentially says "Make sure you are editing a file in the repo before issuing the `:Gedit` command" I would accept it. – Stephen Rasku Aug 02 '16 at 22:02

2 Answers2

3

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_%

Peter Rincker
  • 43,539
  • 9
  • 74
  • 101
0

Use the "git show" command to get the files/versions you want to compare:

> git show version1:file1 > any_name_1
> git show version2:file2 > any_name_2

Then open the files in gedit editor or (better) use some diff tool like, for example, KDiff3 to see the differences between the two files/versions.

> kdiff3 any_name_1 any_name_2