How to make git log --graph the default value

very similar to this question: How to make git default logging

I would do git logdo git log --graph. I suggested that I could add something like graph = trueto the section of [log]my file ~/.gitconfig, but this did not work, and none of the other 28 things that I tried to put in the section were done [log]. :(

I expect to be prompted to add a type alias git lg. I do not want to create an alias. I have two reasons for this:

  • my fingers have been typing git logfor over ten years now and I'm not interested in changing this
  • As a result of my career, I am very conservative in using pseudonyms. I can’t add, and I can always add, my nickname for many thousands of machines with which I end up interacting with a cloud engineer. I use git on multiple machines, and I want to git logbe the single command that I use to display git log.

UPDATE: I was thinking about how to do this, but I hate it. The idea is to create a bash script called gitand put it somewhere in my path before /usr/bin/git. All he would do is call /usr/bin/gitwith any arguments if he is not log, in which case he will do the same, but stick on --graph./me shudders

+4
source share
1 answer

I dont know:

For example, you can define a bash function that would add an option

function do_git {
  cmd=$1
  shift
  extra=""
  if [ "$cmd" == "log" ]; then
    extra="--graph"
  fi
  "`which git`" "$cmd" "$extra" "$@"
}

Then add a wrapper or alias for the do_git link.

The advantage is that the function is part of your point files, which you can use as a git repository and replicate on your computers. See For example: Managing Dotfiles with Git "

+1
source

Source: https://habr.com/ru/post/1675392/


All Articles