
A better git log - bitsweet
http://coderwall.com/p/euwpig?i=3&p=1&t=git
======
qznc
Instead of hardcoding those colors, I'd suggest:

    
    
      git config --global color.ui "auto"
    

Now, this already gives you most of articles info:

    
    
      git log --decorate --graph --oneline

------
gioele
Strange but true, the widespread `git lola` has not been mentioned yet.

    
    
      [alias]
        lol = log --graph --decorate --pretty=oneline --abbrev-commit
        lola = log --graph --decorate --pretty=oneline --abbrev-commit --all
    

<http://blog.kfish.org/2010/04/git-lola.html>

~~~
sant0sk1
Even simpler (git 1.7.7, YMMV)

    
    
        [alias]
          lol = log --graph --decorate --oneline
          lola = log --graph --decorate --oneline --all

------
gilini
Hm, I think something's missing from the post... Oh, yes, proper attribution.

I saw this months ago in a 2010 blog post:
<http://www.jukie.net/bart/blog/pimping-out-git-log>

It's the exact same alias, sans "--date=relative".

The guy from jukie.net also shares his entire .gitconfig, I built mine from it
and highly recommend at least taking a peek:
<http://www.jukie.net/~bart/conf/gitconfig>

------
ngkabra
I find myself using these aliases regularly:

    
    
        df = diff --color --color-words --abbrev
        st = status -s
        l = log --graph --pretty=oneline --abbrev-commig --decorate
    

There are a lot more at this stackoverflow thread:
[http://superuser.com/questions/169695/what-are-your-
favorite...](http://superuser.com/questions/169695/what-are-your-favorite-git-
aliases)

~~~
keporahg
Is there a way to make the filenames in a 'git diff' stand out/coloured? I
always have trouble figuring out where one file's diff ends and the next one
begins.

~~~
gemma
My favorite: git diff --color-words=.

~~~
keporahg
What's the difference between 'git diff --color-words' and what you posted?

------
snissn
tig is cool too. It's an ncurses based interface for exploring git history.
apt-get install tig; and then run tig; in any directory that's a git repo

~~~
bostonvaulter2
+1 for tig. tig blame is also excellent, you can easily drill down to see who
changed a line. Plus tig is a great replacement for git log since it launches
in around 0.25 seconds compared to 1+ seconds for gitk and other graphical
viewers.

~~~
davidw
M-x vc-annotate does a nice 'blame', along with color coding to show the age
of changes.

~~~
antihero
> M-x vc-annotate

Could you explain this further? I think I'm being thick.

~~~
davidw
Sorry, should have added "In Emacs ...".

You don't even need magit to get some nice git interaction.

------
aguynamedben
I use 'git h', which is very similar. It was gifted to me when I moved to SF.

(in ~/.gitconfig under the [alias] section...)

h = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s
%Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date=relative

[https://img.skitch.com/20120619-c9xq67ysdbmrasmfgur6raba1d.p...](https://img.skitch.com/20120619-c9xq67ysdbmrasmfgur6raba1d.png)

I'd love to see how stuff like this spreads. I just use git h because the
person that gave it to me used that.

~~~
suchire
A bit off topic: I like the font you're using on your console screenshot, but
I'm having trouble narrowing down what it is. Do you mind telling us?

~~~
mcantor
Looks like Inconsolata [1] to me. The slashes are set slightly higher than the
pipe, the asterisk is vertically center-aligned (as opposed to super-
positioned as with Consolas, Monaco, Vera Sans Mono and others), a distinctive
upward curve on its lowercase 'y', and it has a looptail lowercase 'g'.

[1] - <http://levien.com/type/myfonts/inconsolata.html>

------
rachelbythebay
This page looks rather surprising with Javascript disabled. It seems to be
leaking all of the "behind the scenes" details which ultimately become the
post, like this:

    
    
        Just type in: git log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' 
    

That seems ... suboptimal.

~~~
joshzayin
I think that's just what you're supposed to type in.

(I see that too, with JS enabled, and if you view source you can see that that
was intentional based on the &gt; and &lt;.)

------
shaggyfrog
Your screenshots are JPEGs; they would look much better as PNGs.

~~~
danielweber
Also I should be able to click on the image, instead of the link below the
image, to see it fullsize.

------
drtse4
A few slightly better aliases with graphs on the left:

lg50 = "!git log --graph --abbrev-commit --date=relative
--pretty=format:'%x00%h%x00%s%x00%cd%x00%an%x00%d' | gawk -F '\\\0' '{ printf
\"%s\\\033[31m%s\\\033[0m %-50s \\\033[32m%14s\\\033[0m
\\\033[30;1m%s\\\033[0m\\\033[33m%s\\\n\", $1, $2, gensub(/(.{49}).{2,}/,
\"\\\\\\\1…\",\"g\",$3), $4, $5, $6 }' | less -R"

lg80 = "!git log --graph --abbrev-commit --date=relative
--pretty=format:'%x00%h%x00%s%x00%cd%x00%an%x00%d' | gawk -F '\\\0' '{ printf
\"%s\\\033[31m%s\\\033[0m %-80s \\\033[32m%14s\\\033[0m
\\\033[30;1m%s\\\033[0m\\\033[33m%s\\\n\", $1, $2, gensub(/(.{79}).{2,}/,
\"\\\\\\\1…\",\"g\",$3), $4, $5, $6 }' | less -R"

Note: i've been using them for some time, i don't even remember who was the
original source...

On an unrelated note, does someone remember how to add code sections? :)

~~~
dbaupp
Try indenting by a few spaces (I think it is four).

~~~
saraid216
Two spaces.

------
btown
An open-source git client for OS X which I think is criminally underused is
Laullón's fork of GitX at <http://gitx.laullon.com/> ... it's a beautiful and
full-featured interface that feels right at home in the GUI. Can't beat the
price, and it's light-years ahead of GitHub for Mac.

~~~
josegonzalez
SourceTree is what I use, but even that is falling apart at the size of our
Git Repo. GitX just falls over for me.

~~~
pnathan
I use SourceTree, but it is _slow_.

------
nobrains24
Nice.

Why is the last -- needed? This restricts giving other wise optional flags to
git log.. Can list last n commits for example.

------
mkl
The final example with "-p" doesn't seem to work, because of the "--". That
"--" shouldn't be needed most of the time, and can be manually added if you
want to specify file names that clash with branch names, etc. Otherwise, this
is really neat.

------
dacort
I also find it very helpful to spiff up my prompt when changing into a git
repo:

[http://railstips.org/blog/archives/2009/02/02/bedazzle-
your-...](http://railstips.org/blog/archives/2009/02/02/bedazzle-your-bash-
prompt-with-git-info/)

~~~
lobo_tuerto
Tried it, for some reason isn't working on my system.

Then found this: <http://volnitsky.com/project/git-prompt/> and I'm loving it!

------
xyzzyb
If you like this you should already be subscribed to Destroy All Software:
outstanding value for the dollar. I actually prefer Gary's "git r" and "git l"
to this.

If you really want to skip on the awesomeness that is DAS, he has his dotfiles
up on github that are chock full of great tidbits:
<https://github.com/garybernhardt/dotfiles>

------
danso
Does anyone have a setup where the git log (perhaps with grep) is synced with
their public changelog file?

------
kschults
Is there a way to limit this to the most recent N (either hard-coded or as an
input) entries? It's a bit slow to load when it has to load all of the history
ever, and I usually only care about at most the last couple dozen commits.

~~~
jeltz
The built in automatic paging in git already makes sure it does not have to
load all history. And --graph is what makes it slow. Adding a limit with git
lg -10 seems to take about the same time as with no limit at all.

~~~
kschults
Ah, thanks for the correction.

Knowing that, this doesn't really matter, but "git lg -10" produces no output
at all for me.

~~~
saraid216
Really? "git lg -10" works perfectly for me, exactly as I expect. Did you add
a "--" to the end accidentally, maybe?

~~~
kschults
Indeed I was. That was in the shortcut when I originally looked at it. He has
since edited it out. Thanks!

------
hhartz
thanks! A minor improvement would be to put tree-ish at the end;

    
    
        log --graph --pretty=format:'%Cred%h%Creset - %s %Cgreen(%cr) %C(bold blue)<%an>%Creset %C(yellow)%d%Creset' --abbrev-commit --

------
sathishmanohar
My only complaint is, I write long commit messages, since the commit messages
are shown in single line, it overflows the viewing area. so, if there are
linebreaks for longer git messages, it would be awesome.

~~~
jherdman
Git best practices say the first line in your commit message should be no more
than 50 characters. Subsequent lines should be wrapped at 80 characters. See
[http://tbaggery.com/2008/04/19/a-note-about-git-commit-
messa...](http://tbaggery.com/2008/04/19/a-note-about-git-commit-
messages.html)

~~~
sathishmanohar
I've been using multiple lines in my log messages, but didn't know about
second blank line.

I tried as per pilgrim689's comment, Now everything is fine with --oneline
argument.

Thanks.

------
orefalo
This is not really new, for those looking into a smart, user friendly git
client, try G2 - <http://orefalo.github.com/g2/>

------
mise
How do you keep track of such changes across machines? In a dotfiles git
repository, and making a symbolic link to your git configuration stored there?

~~~
felixhummel
That's exactly how I do it. <https://github.com/felixhummel/configs#readme>

------
kgc
Many people don't realize there's a graphical interface built into git: gitk

------
danielweber
What's the options to make git show the files that changed in each diff?

~~~
anders0
Apart from `-p` and `--name-status`, there’s also `--stat` for the
`++++++++----` things for each file.

------
dereferenced2
wow, this is amazing. git log has options? and you can use them? who knew.

------
anaheim
"Look, here's a pretty way to configure git! This can also be done in these 17
other ways, wheeeee! It's 2012 and the top article is how to configure colours
in 'git log'"

Seriously, boffins. Stop posting this stuff already. Better techniques are
nice, but good only if they're revolutionary (like that Light Table editor).
We need more new, ground-breaking stuff and less arrangements of Linus's Lego
bricks.

~~~
epaga
"good only if revolutionary" sure would make for a sparse & boring HN front
page...

I appreciate this tip (and upvoted it) as I hadn't thought of the idea before.
Revolutionary? No. Helpful? Absolutely.

~~~
gioele
> "good only if revolutionary" sure would make for a sparse & boring HN front
> page...

Sparse yes, boring I don't think so.

