Vim:Fugitive:Glog - How to get commits for current file rather than revisions
Asked Answered
K

4

28

Currently, if I type :Glog I get the list of revisions for the current file.

If I type :Glog -- I get the list of commits for all files.

What do I need to type to get the list of commits for the current file?

Keikokeil answered 20/9, 2013 at 19:48 Comment(0)
K
12

I figured it out. I found it here.

:Glog -- %
Keikokeil answered 20/9, 2013 at 19:54 Comment(1)
How is this the accepted answer when the link referred cites tpope explicitly stating: "Fugitive provides the -- % for you, and if you give a -- yourself, it assumes you want something other than the current file, drops that behavior, and opens the commit instead."Curtate
S
39

For sake of completeness, once you have the revisions loaded in your buffer, you can browse through them by opening the quickfix list

:Glog -- %
:copen

Load the last 10 commits for the current file

:Glog -10 -- %
Soap answered 20/3, 2014 at 14:8 Comment(1)
And appending a ! will prevent the first match to open. :Glog! -- % Will just fill the quickfixt list without opening the first.Queer
C
13

I use

:0Gclog

It puts the commits history of current file into quick fix so that you can use ]q or [q to go through them

Note that the usage supports range: :{range}Gclog. So you can use any range, e.g. :1Gclog or use a visual mapping:

vmap <leader>gl :Gclog<CR>
Cassino answered 10/6, 2021 at 23:11 Comment(3)
What does the number represent? When I tried it here :0Gclog populated the quickfix list with the log history and :1Gclog, :2Gclog etc populated it with the first commit ever.Amylase
@JoãoPesce The number(s) represents the range in the file to check log for. 0 represents the whole file. Use :help :Gclog for the official description.Servitude
After :0Gclog, you can use dd to get a diff between the current commit and the previous one. See also this.Ticktock
K
12

I figured it out. I found it here.

:Glog -- %
Keikokeil answered 20/9, 2013 at 19:54 Comment(1)
How is this the accepted answer when the link referred cites tpope explicitly stating: "Fugitive provides the -- % for you, and if you give a -- yourself, it assumes you want something other than the current file, drops that behavior, and opens the commit instead."Curtate
L
1
:Git log -- %

I also like adding -p/--patch to see exactly what was changed.

Leafage answered 7/3 at 15:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.