546

Killswitchcollective.com's old article, 30 June 2009, has the following inputs and outputs

git co master
git merge [your_branch]
git push

upstream    A-B-C-D-E            A-B-C-D-E-F-G
                 \        ---->               \
your branch       C-D-E                        G

I am interested how you get the tree like-view of commits in your terminal without using Gitk or Gitx in OS/X.

How can you get the tree-like view of commits in terminal?

snv
  • 133
  • 1
  • 11
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
  • 2
    It's not important to the question, but the article in question is no longer available. A cached copy is available via the Internet Archive: https://web.archive.org/web/20110831142839/http://killswitchcollective.com/articles/36_git_it_got_it_good – Alan De Smet Aug 22 '17 at 21:07

6 Answers6

962

How can you get the tree-like view of commits in terminal?

git log --graph --oneline --all

is a good start.

You may get some strange letters. They are ASCII codes for colors and structure. To solve this problem add the following to your .bashrc:

export LESS="-R"

such that you do not need use Tig's ASCII filter by

git log --graph --pretty=oneline --abbrev-commit | tig   // Masi needed this 

The article text-based graph from Git-ready contains other options:

git log --graph --pretty=oneline --abbrev-commit

git log graph

Regarding the article you mention, I would go with Pod's answer: ad-hoc hand-made output.


Jakub Narębski mentions in the comments tig, a ncurses-based text-mode interface for git. See their releases.
It added a --graph option back in 2007.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    I just tested it on my repo. It works but I am on Windows with MSysGit1.6.3. – VonC Jun 30 '09 at 15:57
  • files.getdropbox.com is blocked here at work :( I will see your picture in about one hour, time to get home. – VonC Jun 30 '09 at 16:00
  • @Vonc: I now typed two for the first command. I get a similar view as in the picture for the second command. – Léo Léopold Hertz 준영 Jun 30 '09 at 16:01
  • 9
    There is also 'tig', text-mode interface for git (using ncurses), which had graphical history view in terminal before there was '--graph' option to git-log. – Jakub Narębski Jun 30 '09 at 16:50
  • 3
    I find `--decorate` to be indispensable on this sort of a display as well -- it shows you ref names (branches, remote and local) alongside the abbreviated commit name. – Matt Enright Mar 16 '12 at 20:49
  • @MattEnright I agree, and use it here: http://stackoverflow.com/questions/7022890/how-to-display-the-tag-name-and-branch-name-using-git-log-graph/7023272#7023272. But beware of the colors used by decorate: http://stackoverflow.com/questions/5889878/color-in-git-log/5892582#5892582 – VonC Mar 16 '12 at 21:57
  • @MattEnright and for certain tasks, decorate isn't the best option: http://stackoverflow.com/questions/5659273/how-can-i-know-what-was-the-latest-changes-made-to-a-branch – VonC Mar 16 '12 at 22:01
  • I've found out that this is an easier way to remember git log --graph --oneline – Ronaldo Felipe Oct 13 '17 at 19:23
356

A solution is to create an Alias in your .gitconfig and call it easily:

[alias]
    tree = log --graph --decorate --pretty=oneline --abbrev-commit

And when you call it next time, you'll use:

git tree

To put it in your ~/.gitconfig without having to edit it, you can do:

git config --global alias.tree "log --graph --decorate --pretty=oneline --abbrev-commit"  

(If you don't use the --global it will put it in the .git/config of your current repo.)

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
Marouane Gazanayi
  • 5,063
  • 6
  • 39
  • 58
  • 3
    How is this not a default alias? I guess it would make Git's CLI slightly less infuriating to use and we can't have that... – Timmmm Jul 03 '19 at 11:48
141
git log --oneline --decorate --all --graph

A visual tree with branch names included.

Use this to add it as an alias

git config --global alias.tree "log --oneline --decorate --all --graph"

You call it with

git tree

Git Tree

Sebastian Patten
  • 7,157
  • 4
  • 45
  • 51
70

tig

If you want a interactive tree, you can use tig. It can be installed by brew on OSX and apt-get in Linux.

brew install tig
tig

This is what you get:

enter image description here

Community
  • 1
  • 1
Mohsen
  • 64,437
  • 34
  • 159
  • 186
7

I would suggest anyone to write down the full command

git log --all --decorate --oneline --graph

rather than create an alias.

It's good to get the commands into your head, so you know it by heart i.e. do not depend on aliases when you change machines.

Saxophonist
  • 677
  • 9
  • 16
  • 15
    It is actually `git log --all --decorate --oneline --graph`, after the mnemonic `git log a dog` ;) – VonC Mar 11 '19 at 13:32
  • @VonC The final result is the same. Anyway, I agree with you. Thanks for the feedback. – Saxophonist Mar 12 '19 at 17:35
  • Yes, that is what the smiley `;)` at the end of my previous comment was trying (imperfectly) to convey: you can use those option in any order you want. I just find "log a dog" funny :) – VonC Mar 12 '19 at 17:41
  • 1
    Or you could `scp ~/.bashrc root@remote:~/` and your aliases move over real quick. – Got To Figure May 15 '19 at 13:28
6

Keeping your commands short will make them easier to remember:

git log --graph --oneline
JSON C11
  • 11,272
  • 7
  • 78
  • 65