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.
Top comments (25)
I forget where I found this:
Then
gtree
in your repo.I'm totally going to borrow this. I add a '%G?' to my format so it's easy to see which commits are signed or not.
Yeah, you could add git alias to long command.
OoOoOo me Gusta!
This is great, thanks for sharing.
I'm with you, Andrew - I think
git log
is my favorite part about Git!I personally love using
git log -S $QUERY
to find out "hey, when did $QUERY appear in/disappear from the repository?" I was trying to figure out some things about what was removed between GTK 2 and 3, and-S
is perfect for finding things like that!Another log feature I love answers the question "I know I made this commit recently, and it contains the substring 'hello' - but which branch was it on?" For that I use
git log --author=hoelz -G hello --all --source
, which will print commits I wrote whose diff contains "hello". It searches across all branches, and prints the branch it used to find each commit.tux0r - have you written any posts on Pijul or Darcs? If not, you totally should! I think it would be really interesting to see a fresh perspective on what else is out there in the VCS world, and it would be a nice chance to highlight what non-Git source control systems bring to the table. I know a lot of people feel like Git has "won", but I myself have a soft spot for Mercurial, and I think having competition is essential to innovation in the space!
I have found these git aliases to be helpful. Paste this into your
~/.gitconfig
file.git lg
git lg2
git lg3
courtesy of: stackoverflow.com/a/34467298/504836
There seems to be a typo in the last command for
git log --online --graph --color
it should be
git log --oneline --graph --color
Yes! My bad. I'll fix it when I get a chance.
Electron apps don't have to be slow....
Nah, Atlassian does only what makes sales go high. Got a serious bug in Atlassian product? Wait few years until we finish new shiny graphical UI first!
Just trying to start out on the right foot.
I haven't used Darcs/Pijul before. But, I plan on writing somethings about merging/rebasing difficult branches. Which, probably isn't too different than what most people do, but there are ways to make merging less painful.
Yeah, I have used GitKraken, its the closest thing to a usable git GUI that I would use.
I was disappointed with SourceTree.
I like Cycligent.
I thought GitKraken had the prettiest UI of the front-ends I've seen.
The only two problems I experienced with GitKraken, which is from a year or two ago:
Sourcetree is pretty good, though they have some annoying bugs once in a while.
Maybe you'd enjoy
git-screensaver
. 🙂No, Git and Mercurial are very different.
In Git, branches are just a point in a history, similar to tags, just with regular updates.
In Mercurial, every commit belongs to a specific branch and it matters, which branch you merge into which one.
Besides that, Git has many GUIs, but none is good.
They often are incomplete, difficult to use and do a lot of unintended stuff in the background.
Mercurial has TortoiseHG, which just works like the command line stuff, and you can use many advanced command line features in GUI as well.
Some comments may only be visible to logged-in visitors. Sign in to view all comments.