Red Green Repeat Adventures of a Spec Driven Junkie

git log graph all

I’m playing around with git and seeing how it’s internal works in preparation for an upcoming talk.

ÉdouardManet-MadameManetAtBellevue

source

One thing I discovered: git can display its log as a graph with command: $ git log --graph

When used on a single branch, this is the output:

vagrant@ubuntu-xenial:/vagrant$ git log --graph
* commit 0490cdf134cffe95ffe0ed3782513c56eb9505d0 (HEAD -> rebase_testing)
| Author: Andrew Leung <andrew@ualberta.net>
| Date:   Thu Apr 18 07:59:12 2019 -0400
|
|     FIX: Enhance important file
|
* commit c2a5c4a7b45305c52dc6c729d813974689391cc9 (testing)
| Author: Andrew Leung <andrew@ualberta.net>
| Date:   Thu Apr 18 07:58:12 2019 -0400
|
|     FEATURE: Add testing file
|
* commit ec0dde385a2d36db33451ec977d796d0c03cc6b4
| Author: Andrew Leung <andrew@ualberta.net>
| Date:   Thu Apr 18 07:54:57 2019 -0400
|
|     FIX: Add important file contents
|
* commit ef43cae09d13683c8cdf7383239fcb4524cb911d
| Author: Andrew Leung <andrew@ualberta.net>
| Date:   Thu Apr 18 07:54:13 2019 -0400
|
|     FEATURE: include important file
|
* commit 597d77176f9604ce55e094262ddec21671b0f149
  Author: Andrew Leung <andrew@ualberta.net>
  Date:   Thu Apr 18 07:53:12 2019 -0400

      initial commit

Which is nice, and does not show anything more than the $ git log command:

vagrant@ubuntu-xenial:/vagrant$ git log
commit 0490cdf134cffe95ffe0ed3782513c56eb9505d0 (HEAD -> rebase_testing)
Author: Andrew Leung <andrew@ualberta.net>
Date:   Thu Apr 18 07:59:12 2019 -0400

    FIX: Enhance important file

commit c2a5c4a7b45305c52dc6c729d813974689391cc9 (testing)
Author: Andrew Leung <andrew@ualberta.net>
Date:   Thu Apr 18 07:58:12 2019 -0400

    FEATURE: Add testing file

commit ec0dde385a2d36db33451ec977d796d0c03cc6b4
Author: Andrew Leung <andrew@ualberta.net>
Date:   Thu Apr 18 07:54:57 2019 -0400

    FIX: Add important file contents

commit ef43cae09d13683c8cdf7383239fcb4524cb911d
Author: Andrew Leung <andrew@ualberta.net>
Date:   Thu Apr 18 07:54:13 2019 -0400

    FEATURE: include important file

commit 597d77176f9604ce55e094262ddec21671b0f149
Author: Andrew Leung <andrew@ualberta.net>
Date:   Thu Apr 18 07:53:12 2019 -0400

    initial commit

Adding $ git log --graph with the --all command produces something a little more interesting:

vagrant@ubuntu-xenial:/vagrant$ git log --graph --all
* commit 0490cdf134cffe95ffe0ed3782513c56eb9505d0 (HEAD -> rebase_testing)
| Author: Andrew Leung <andrew@ualberta.net>
| Date:   Thu Apr 18 07:59:12 2019 -0400
|
|     FIX: Enhance important file
|
| *   commit 41981bc2b913166461296d51d17a217b5b6ff622 (merge_testing)
| |\  Merge: c02bd5f c2a5c4a
| |/  Author: Andrew Leung <andrew@ualberta.net>
|/|   Date:   Thu Apr 18 08:01:31 2019 -0400
| |
| |       Merge branch 'testing' into merge_testing
| |
* | commit c2a5c4a7b45305c52dc6c729d813974689391cc9 (testing)
| | Author: Andrew Leung <andrew@ualberta.net>
| | Date:   Thu Apr 18 07:58:12 2019 -0400
| |
| |     FEATURE: Add testing file
| |
| * commit c02bd5fa53e0513d91b0e2545573bb8f18acb9a5 (master)
|/  Author: Andrew Leung <andrew@ualberta.net>
|   Date:   Thu Apr 18 07:59:12 2019 -0400
|
|       FIX: Enhance important file
|
* commit ec0dde385a2d36db33451ec977d796d0c03cc6b4
| Author: Andrew Leung <andrew@ualberta.net>
| Date:   Thu Apr 18 07:54:57 2019 -0400
|
|     FIX: Add important file contents
|
* commit ef43cae09d13683c8cdf7383239fcb4524cb911d
| Author: Andrew Leung <andrew@ualberta.net>
| Date:   Thu Apr 18 07:54:13 2019 -0400
|
|     FEATURE: include important file
|
* commit 597d77176f9604ce55e094262ddec21671b0f149
  Author: Andrew Leung <andrew@ualberta.net>
  Date:   Thu Apr 18 07:53:12 2019 -0400

      initial commit

There are indicators of where different branches start to diverge.

  • commit: c02bd is the master branch.
  • commit: c2a5c is the testing branch, which is not on the master branch.
  • commit: 41981 is the merge_testing branch, which is a combination of the master branch and testing branch.
  • commit: 0490c is the rebase_testing branch, which is a direct descendant of the testing branch.

Combining with --oneline

vagrant@ubuntu-xenial:/vagrant$ git log --graph --all  --oneline
* 0490cdf (HEAD -> rebase_testing) FIX: Enhance important file
| *   41981bc (merge_testing) Merge branch 'testing' into merge_testing
| |\
| |/
|/|
* | c2a5c4a (testing) FEATURE: Add testing file
| * c02bd5f (master) FIX: Enhance important file
|/
* ec0dde3 FIX: Add important file contents
* ef43cae FEATURE: include important file
* 597d771 initial commit

Conclusion

git log --graph --all produces a nifty graph on the command-line to visualize the current state of the repository and all the branches.