1

I have this alias.

alias viewtree='git log --graph --pretty=format:"%C(cyan)%h %C(bold blue)%cd %C(blue)%cn %Creset%C(bold magenta)%s %C(green)%d" --date=local --branches'

I have one issue with it, it is not sorted by recently commited. How can I edit this to sort the list in the way "git log" sorts it.

RvBVakama
  • 91
  • 1
  • 8
  • Possible duplicate of [How can I make git log order based on author's timestamp?](https://stackoverflow.com/questions/8576503/how-can-i-make-git-log-order-based-on-authors-timestamp) – Chris Prolls Oct 17 '18 at 07:21
  • You can't: `git log --graph` forces `--topo-order`, which changes the sorting. This is because the internal graph-drawing algorithm requires a topological sort, rather than a chronological sort. (You can of course write your own graph-drawing algorithm that does not require this, but then you will use `git rev-list`, as `gitk` does for instance, rather than relying on `git log --graph`.) – torek Oct 17 '18 at 07:22
  • torek, is there a way to force recent order, as I like the graph ascii. I don't mind if it is incoherant. – RvBVakama Oct 17 '18 at 07:26
  • You *can* combine `--graph` with `--date-order` or `--author-date-order`. But in all cases, `git log --graph` refuses to mingle the parents of a commit, while without `--topo-order`, `git log` is happy to do so. (See the `git log` and `git rev-list` documentation, particularly the descriptions of these three options.) – torek Oct 17 '18 at 07:32
  • ok thanks. btw, gitk is not a command on my terminal – RvBVakama Oct 17 '18 at 07:33
  • `gitk` is a Tcl/Tk script that uses X11 windowing. If you have a Linux box, it should just work, but if you have anything else, it requires some setup. (BTW my description of `--date-order` and `--author-date-order` above is not right, but it's too late to edit the comment... They may do what you want, so try them out.) – torek Oct 17 '18 at 07:44
  • yes date order did nothing and im using termux on the playstore – RvBVakama Oct 17 '18 at 08:01

1 Answers1

2

You may look for the --date-order/--topo-order optional arguments.

Otherwise, here is the command I use for this :

$> git log --pretty="format:%at %C(yellow)commit %H%Creset\nAuthor: %an <%ae>\nDate: %aD\n\n %s\n" | sort -r | cut -d" " -f2- | sed -e "s/\\\n/\\`echo -e '\n\r'`/g" | tr -d '\15\32' | less -R

Take a look at it, you may found it better ;)

Chris Prolls
  • 89
  • 12