When I run git log, what exactly is the editor git log is using?

Also:

  1. Is there anyway I can use vim as my default editor for git log?
  2. If I want to search against the git log, what's the best way? Now I'm doing something like: git log | grep bla.
有帮助吗?

解决方案

The git log command pipes it's output by default into a pager, not an editor. This pager is usually less or more on most systems. You can change the default pager to vim with the command:

git config --global core.pager 'vim -'

Now you can search using vim functionality with / as usual.

其他提示

You may want to look at viewlog.

It gives you a terminal gui interface to all commits. It will also open the file in the editor of your choice. You can search for relevant commits using the --grep flag.

This worked for me: git log | vim -R -

I had write a bash script to switch from using vim as editor to diff-so-fancy.

VT() {
    gitlogflag=true
    if [ -e "$HOME/.myscriptvar" ] ; then
        gitlogflag=$(cat "$HOME/.myscriptvar")
    fi
    if [ "$gitlogflag" = true ]; then
        git config --global pager.show "vim -c '%sm/\\e.\\{-}m//g' -c 'setlocal buftype=nofile' -c 'set ft=diff' +3 -";
        gitlogflag=false
    else
        git config --global pager.show "diff-so-fancy | less --tabs=1,5 -RFX";
        gitlogflag=true
    fi
    echo "$gitlogflag" > $HOME/.myscriptvar
}

I recommend you to use diff-so-fancy.

If you just want to use vim as your git log editor git config --global pager.show "vim -c '%sm/\\e.\\{-}m//g' -c will satisfy you.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top