Hacker News new | past | comments | ask | show | jobs | submit login
A better git log (coderwall.com)
131 points by 6ren on June 7, 2013 | hide | past | favorite | 57 comments



Want better? Use tig - https://github.com/jonas/tig


I'm so annoyed. I've heard "tig is amazing" so I go to github... hmm, no screenshots or examples. Oh, there's a homepage. Compile instructions but also no screenshots or examples.

"Tig is a git repository browser that additionally can act as a pager for output from various git commands."

It happens all over github. Even UI projects fall prey to this problem, which is especially egregious. I want to grab these project owners by the shoulders, shake them, and yell DON'T YOU WANT ME TO USE YOUR PROJECT? THEN SHOW ME WTF IT DOES!!


There are definitely screenshots on the website (http://jonas.nitro.dk/tig/screenshots/)


Oh I see, in the screenshots directory. That's nice. Point still stands, put your screenshots front and center.


This. Tig is amazing


Everytime I think a feature doesn't exist in tig, I search the docs for it... facepalm that I didn't realize it could do that and love it ever so much more.



I use something similar:

    [alias]
        lt = log --graph --pretty=changes
    [pretty]
        changes = format:%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset
It's nice to be able to separate the format specifier from the alias itself. Makes the configuration a lot cleaner.


i like your config i'll borrow some of that, here's my current one

https://gist.github.com/fishman/091d32da731c8b841c94

EDIT: I either already did many many moons ago, or we would had the same master :p


What is the purpose of your "st" alias?


good catch, that's pretty much a leftover from pre

    git status --short
times, thanks


What is that color scheme? It's pretty great.



So everyone who started visiting Hacker News 352 days ago shouldn't get to see this on HN?


No, but he may be interested in the previous comments. That's where most good things are, anyway ;)


Good call. I hadn't thought of that. Reddit has given me a cynical outlook when someone points out that something is a "repost".


What gave you that idea?


Reddit has given me a cynical view when someone points out "This has been posted before!". I apologize jacquesm.


Yep, first thing I also thought is "That's old!"


Off topic, but what's with the trend of not showing dates on blogs/blogging services? Just overlooked or hidden on purpose? Even the comments don't have dates.


My guess is that you're less likely to read something if you judge it out of date by the post date. But I hate it.


Here are two variations that I find useful day-to-day.

1. Graph showing commits on all branches, decorated with branch and tag names, short commit hashes, committer name and commit comment:

    git log --graph --all --abbrev-commit --pretty=format:'%C(red)%d%x20%C(yellow)%h%x20%C(green)%an%x20%Creset%s'
2. List commits in HEAD that aren't in master:

    git log --abbrev-commit --pretty=format:'%C(yellow)%h%x20%C(green)%an%x20%Creset%s' master..HEAD


you can get a slightly more reliable list of commits that are in HEAD that aren't in master using --not:

    git log HEAD --not master
or the shorthand

    git log HEAD ^master


What terminal does this work in? I just got raw escape codes.


Oh, I had no idea it wasn't portable, sorry. I'm using iTerm2 on OSX, but maybe worth trying them without the colouring:

    git log --graph --all --abbrev-commit --pretty=format:'%d%x20%h%x20%an%x20%s'
    git log --abbrev-commit --pretty=format:'%h%x20%an%x20%s' master..HEAD


Those work, thanks. I'm on Linux using xfce4-terminal at the moment. There's probably a way to get the color codes to work, but I don't know it.


Which PAGER are you using? If it's less, try setting PAGER='less -R', or LESS=-R to enable raw control character output.


Bingo! Nothing to do with the terminal at all! Thanks!


What I want is filenames in the git log, just a list of which files were touched in each commit. My messages aren't distinct enough without them.


try one of the following:

    git log --stat
    git log --numstat
    git log --name-only
These flags can be passed to most git commands which show revisions, including diff and show.


Sure, but they can't be integrated into a line-per-commit log without fiddly scripting.


What is wrong with git whatchanged? Will use your pretty format for the message, but then show the files. Right?


Is it possible to get one line per commit from this? I can only get one line per file.

By one line per commit, I mean something along the lines of:

    56c6861 - add reflist (4 months ago: joe) Joe/Manu.bbl Joe/Manu.bib Joe/Manu.bst ...
    5ed70cc - (origin/master) add tests; change .gitignore (5 months ago: cas) ./.gitignore test/integ.lua test/refs ...
    d3c5de1 - replace Manifest; add converter (5 months ago: cas) ./Manifest maked/tex2html.lua maked/tex2html.cfg


Apologies for not responding on this. I am not aware of anything that does this right off... Would probably be pretty easy to script. If you are still interested, I could probably get the basics of this rolling.


Thanks. I can script this as well - there's nothing fundamentally tricky here, but generating nice output is usually fiddly.


Yes, or at least the basename of the file that changed most. I think you can't include filenames using --pretty though, you'd have to write a new script.


`git whatchanged` is what you want, it shows the files changed and the commit message.


    git log --stat


I use a slight variation to this: https://github.com/magnetikonline/dotfiles/blob/master/.gitc... more formatting/color that anything.

As noted below, tig is well worth the install for getting around your logs/diffs on the command line.


My preferences: http://i.imgur.com/UtxK6LZ.png (source in my github/dotfiles; this is suitable mostly for linear history without merges). Displays 10 items by default, for more, I write explicitly from command line.


For a high level overview of your branches I still think http://stackoverflow.com/questions/1057564/pretty-git-branch... is the best git log


I prefer my own alias over that, less clutter:

  glg='git log --pretty=format:'\''%Cred%h%Creset%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset'\'' --abbrev-commit --date=relative'


FYI: %h implies --abbrev-commit and %cr implies --relative-date/--date=relative (Commit date Relative).


I use something similar so often that I made myself a shell alias "gl".


I do the same for various other git commands, such as git checkout ('gc').

The only problem is that this breaks git tabcomp. Haave you (or anyone else) dealt with this?


I choose a middle approach - rather than making loads of new base commands, I just use the aliases, and only for the really common commands

> git co > git st > git ci


Fellow git aliaser, consider shell aliasing git to g!


Me too. And I got it from here: http://alias.sh/compact-colorized-git-log

Which is almost the same as mentioned in this post.


Cheers for the reminder. I've definitely seen this before, but had completely forgot to set it up on my new laptop. Good post.


Coderwall: meta content='width=device-width,initial-scale=1.0,maximum-scale=1.0'

Really??


i use this

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

tig is neat, i need to port it


Is this really anything new?


No love for gitk?


Not only is this a repost, I have seen it on Hacker News several times over the past year. Anyone who is searching for a better Git log will find one without the help of free advertisement on the front page.


Many git novices don't know that the log output can even be changed, and aren't likely to be searching for an alternative syntax. Don't assume that just because you know something, everyone else does, an that the training is useless.

Additionally, the discussions that this post created here in the comments have already given me three new aliases that I didn't know we're possible.


clearly you're not very imaginative. not thinking or realizing you can change the output is naive. there are so many people writing up the same hints it's almost impossible not to run into something like this daily. if you seriously rely on 'discussions' to improve your knowledge you're not really thinking for yourself, are you?


Be careful with that kind of assumption. I've never seen this before, and found it very useful.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: