Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to control the default view of gitk

I use gitk from Git for Windows. By default it seems to open with a view that only displays the currently checked out branch.

I have a different saved view which is the one that I use 90% of the time.

I normally open gitk from the cmd line (by running gitk &), and then have to change the view.

Is there any way to configure gitk to use my preferred view by default?

like image 382
Brondahl Avatar asked Oct 20 '25 01:10

Brondahl


2 Answers

There does not appear to be a feature for this in gitk, however it is pretty easy to manually patch gitk to switch to the first permanent view (located for me in c:\Program Files\Git\mingw64\bin\gitk):

if {[info exists permviews]} {
    foreach v $permviews {
    set n $nextviewnum
    incr nextviewnum
    set viewname($n) [lindex $v 0]
    set viewfiles($n) [lindex $v 1]
    set viewargs($n) [lindex $v 2]
    set viewargscmd($n) [lindex $v 3]
    set viewperm($n) 1
    set viewchanged($n) 0
    addviewmenu $n
    }
    # add these two lines
    set curview [expr {$curview + 1}]
    set selectedview $curview
}

This will always select the first permanent view you defined as the default view. If you want to reorder the views, the (hidden) config file is at %USERPROFILE%\.config\git\gitk. The setting is called permviews.

like image 56
mrexodia Avatar answered Oct 22 '25 04:10

mrexodia


Thanks, @mrexodia. One improvement I was able to make on your answer was to guard the additional lines so that they won't run if cmd-line args were provided:

if {$curview==0} {
    set curview 1 
    set selectedview $curview
}

Also, thanks to this thread for helping me understand that I had to run Git Bash as Administrator to be able to modify the gitk file.

like image 35
Shi Avatar answered Oct 22 '25 05:10

Shi