very similar to this question: How to make git log decorate by default
I would like to make git log
do git log --graph
. I assumed I could add something like graph = true
to the [log]
section of my ~/.gitconfig
file, but it did not work, nor did any of the other 28 things I tried putting into the [log]
section. :(
I expect it will be suggested that I add an alias like git lg
. I do not want to create an alias. I have two reasons for this:
git log
for over a decade and I have no interest in changing thatgit log
to be the solitary command I use to display the git log.UPDATE: I thought of a way to do it, but I hate it. The idea is to create a bash script called git
and put it somewhere in my path before /usr/bin/git
. All it would do is call /usr/bin/git
with whatever arguments are passed, unless it is a log
in which case it will do the same but tack on a --graph
. /me shudders
Note that git log --graph does not show the commits in chronological order. The git help man pages call it --topo-order, topological ordering. “Show no parents before all of its children are shown, and avoid showing commits on multiple lines of history intermixed.”
Without this flag, git log -p <path>... shows commits that touch the specified paths, and diffs about the same specified paths. With this, the full diff is shown for commits that touch the specified paths; this means that "<path>…" limits only commits, and doesn’t limit diff for those commits.
All Git actions (blue buttons) work like that. Even the main git log action itself is a modifiable field: By default it holds log --graph --oneline --pretty=VSCode --author-date-order -n 15000 --skip=0 --all $ (git reflog show --format='%h' stash)
git log can display surprisingly confusing results when the history contains merges. In this post, I’ll walk you through a few parameters that can help clear things up. I’ll start by showing how the default “chronological” order of git log can mislead you when the history contains merge commits.
2017: I don't know of:
For instance, you can define a bash function which would add the option
function do_git {
cmd=$1
shift
extra=""
if [ "$cmd" == "log" ]; then
extra="--graph"
fi
"`which git`" "$cmd" "$extra" "$@"
}
Then add a wrapper or an alias to reference do_git.
The advantage is that the function is part of your dotfiles, that you can manage as a git repo and replicate across your machines. See for instance " Managing Dotfiles with Git"
2022: Note, a log.graph
option is being discussed/implemented.
But: what happens when you type git log --graph
(resulting in git log --graph --graph
)?
Or what if you want a regular git log
? (without the --graph added automatically)
Before Git 2.36 (Q2 2022), "git log --graph --graph
"(man) used to leak a graph structure, and there was no way to countermand "--graph
" that appear earlier on the command line.
A "--no-graph
" option has been added and resource leakage has been plugged.
See commit 087c745, commit dccf6c1 (11 Feb 2022) by Alex Henrie (alexhenrie
).
(Merged by Junio C Hamano -- gitster
-- in commit 8813596, 23 Feb 2022)
log
: add a--no-graph
optionSigned-off-by: Alex Henrie
It's useful to be able to countermand a previous
--graph
option, for example ifgit log --graph
(man) is run via an alias.
I don't think that doing it as default would be what you want in all cases anyway. I am thinking especially of cases when you will want to process the output of git log
or when you add other options that would conflict with --graph
.
So I prefer to go with the idea in your UPDATE and put a little script in my $HOME/bin
, called git
and which comes before the installed git
in my $PATH
.
It looks like this:
#!/bin/bash
function run_git(){
real_git=$(which -a git | sed '2 !d;')
bash -c "$real_git $(printf ' %q' "$@")"
}
if [ -t 1 ]; then
case "$*" in
log)
run_git log --graph
exit $?
;;
esac
fi
run_git "$@"
The function:
git
executable to call.The [ -t 1 ]
test checks that this outputs directly to a terminal, to avoid messing potential scripts/programs/pipes up. (thanks to this question)
Then the case
statement will allow to handle other similar cases simply.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With