I love git log

Andrew Stuntz - Aug 20 '18 - - Dev Community

The title of this post should be IFLG (like IFLS, but ya know with Git).

But it's probably not great to title a post with the f*** word. Ya know.

Git is the best

Really, I love git. I think it is ridiculously useful and when used properly, it can speed up development on a team tremendously. When I was first learning git though, I always got so frustrated by not being able to see what was going on with git, like what were my teammates doing and how did my work fit in with what they were doing?

I tried a few UI's for working with git but was never satisfied, everything seemed clunky and you had to get out of the terminal to go look at the UI and then come back and figure out what you were doing again.

One of my favorite commands when I am working with git repo's is (hopefully unsurprisingly) git log.

This shows a log of all of your commits and the basic command outputs something along the lines of:

commit 8c2ca7c38f50e1d837485edd946916bfdciii20a1 (HEAD -> master, origin/master)
Author: Andrew Stuntz <andrewbstuntz@gmail.com>
Date:   Mon Aug 20 10:20:27 2018 -0700

    Fixes the resetting of form fields on the settings form

commit cc309a7cb45bfcfd7e94a49387086266dff54c05
Author: Andrew Stuntz <andrewbstuntz@gmail.com>
Date:   Mon Aug 20 10:03:46 2018 -0700

    Updates some styling issues and copy

commit 2d848cec12038475b9f12070547653ab212e4e6
Author: Andrew Stuntz <andrewbstuntz@gmail.com>
Date:   Mon Aug 20 08:17:13 2018 -0700

    Add config and format correctly

commit deec64859bc9b2ef74a987437b7864f2183940e
Author: Andrew Stuntz <andrewbstuntz@gmail.com>
Date:   Thu Aug 16 11:11:42 2018 -0700

    First commit, I never know what to put here?

So what do we have going on here?

commit 8c2ca7c38f50e1d837485edd946916bfdciii20a1 (HEAD -> master, origin/master)
Author: Andrew Stuntz <andrewbstuntz@gmail.com>
Date:   Mon Aug 20 10:20:27 2018 -0700

    Fixes the resetting of form fields on the settings form

Overall, it's pretty easy to see the ordering of the commits, top to bottom, first commit to last commit. You get the revision number which uniquely identifies the individual revision. Next to that, you see some more information about your branch in the parentheses, these reference your HEAD (which is what you have checked out now). You also origin/master which means that origin/master is at this commit as well. So your HEAD and origin/master are at the same revision. Then you get an Author and a Date. Finally, you get the commit message. So far so good. Nothing too complicated.

Diving into the git log command

If you do a git log --help you get ample output, in fact one reason I love git is the massive amount of documentation that allow you to really dive into and customize what you want. I'm gonna run through a few of my favorite options that let you really see what is going on in your repository.

The first is git log --graph

Which lets you see a graph of the branches.

* commit 8c2ca7c38f50e1d837485edd946916bfdciii20a1 (HEAD -> master, origin/master)
| Author: Andrew Stuntz <andrewbstuntz@gmail.com>
| Date:   Mon Aug 20 10:20:27 2018 -0700
|
|     Fix the resetting of form fields on the settings form
|
* commit cc309a7cb45bfcfd7e94a49387086266dff54c05
| Author: Andrew Stuntz <andrewbstuntz@gmail.com>
| Date:   Mon Aug 20 10:03:46 2018 -0700
|
|     Update some styling issues and copy
|
*   commit a9b263cacd3240f6d00e7ce401fc6f6c23988cee
|\  Merge: 2d848cec deec4187
| | Author: Andrew Stuntz <andrewbstuntz@gmail.com>
| | Date:   Mon Aug 20 08:19:44 2018 -0700
| |
| |     Merge branch 'master' of some/private/repo
| |
| *   commit deec398745bc9b2ef74a418287b7864f2183940e

Already we are starting to get a little more visual, you see the commit easily from one branch into the master branch. You can also see at the bottom the commit that was made onto that branch before it was merged into the master branch.

The next command I like a lot is git log --oneline

This takes the output and makes each commit a single line, so it vastly increases the amount of commits that you can see at any give time.

8c2ca7c3 (HEAD -> master, origin/master) Fix the resetting of form fields on the settings form
cc309a7c Update some styling issues and copy
a9b263ca Merge branch 'master' of https://github.com/drews256/some/private/repo
2d848cec Add config and format correctly
deec4187 Merge pull request #1303940 from drews256/some-other-branch

Now we have the same amount of information, but succinctly displayed in 5 lines.

You can even combine the two and get git log --oneline --graph.

* 8c2ca7c3 (HEAD -> master, origin/master) Fix the resetting of form fields on the settings form
* cc309a7c Update some styling issues and copy
*   a9b263ca Merge branch 'master' of https://github.com/drews256/some/private/repo
|\
| *   deec4187 Merge pull request #1303940 from drews256/some-other-branch

You get the best of both worlds, you see the graph and branching plus the commits and now its displayed succinctly.

If you have color globally turned on for your git repos, this will display in full color, with each branch having a unique color which makes it very easy to follow. If that isn't the case and you want to add some color to your output, you can run git log --oneline --graph --color and you will see each branch nicely colored for you to explore.

Now you can see what and where your branches are easily and make sure your not working in or on places you shouldn't be.

What are your favorite parts of git?

Thanks atlassian for the cover photo.

. . . . . . . . . . .
Terabox Video Player