Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

For those increasingly rare times I'm not using Magit[0], I have a "git lg" alias I found once through HN[1]:

  git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
I strongly recommend both.

--

[0] - https://magit.vc/

[1] - https://coderwall.com/p/euwpig/a-better-git-log



You should probably avoid `--color`, as it turns on color unconditionally, even if output is going to a file. In older versions of Git the %C color placeholders were unconditional anyway. In modern Git, they respect the normal auto-coloring settings.

You can also drop `--abbrev-commit`, since `%h` abbreviates by default (use `%H` if you want the full hash).


For the lazy:

  git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'"


We must have started from the same source. I've since added displaying message bodies by default, but similar otherwise:

lg = log --graph --date=relative --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset%n%w(0,4,4)%-b%n%n%-N'


You can still add color when not piping or writing to a file with `--color=auto`.

      git config --global alias.lg "log --color=auto --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'"


This is likely to be said, "`--color=auto` is the default setting, so it's not needed." However, it's good to include it here because some users may have changed their default configuration to disable colors. This way `git log` works as their standard workflow and `git lg` for when they need a bit of color.


I use the following since it keeps the abbreviated hash and date of the commit in their own "columns", making it easy to skim:

  git log --date=short --pretty=format:"%C(124)%ad %C(24)%h %C(34)%an %C(252)%s%C(178)%d"


Since we're sharing:

    [pretty]
    	lg = %C(red)%h%C(reset) %C(green)%ci%C(reset) %s %C(bold blue)-- %an%C(reset)%C(yellow)%d%C(reset)
    	lge = %C(red)%h%C(reset) %C(green)%ci%C(reset) %s %C(bold blue)-- %an <%ae>%C(reset)%C(yellow)%d%C(reset)
    	reflg = %C(red)%h%C(reset) %C(green)%ci%C(reset) %s %C(bold blue)-- %an%C(reset) %C(yellow)(%gd)%C(reset)
    [alias]
    	lg = log --pretty=lg
    	glg = log --graph --pretty=lg
    	slg = stash list --pretty=reflg
    	blg = branch --format '%(color:red)%(objectname:short)%(color:reset) %(color:green)%(committerdate:iso)%(color:reset) %(subject) %(color:bold blue)-- %(authorname)%(color:reset) %(color:yellow)(%(refname:short))%(color:reset)'
lg is the normal log, glg is with the graph, slg lists my stashes in the same format (i find the date really helpful), and blg does the same for branches.

blg can't reuse a pretty definition because it uses a completely different formatting language. The fact that Git contains two different but largely equivalent formatting languages is kind of emblematic of its whole design, really.

Like heipei, i put the fixed-width bits on the left so that they line up. I try to use consistent and distinctive colours for everything; mostly that's obvious, but yellow draws an equivalent between branch names for the normal and branch logs, and stash refs for the stashes. Including committer name for stashes is perhaps foolish consistency, although it would be useful if you do pair programming and use something like git-duet.


> The fact that Git contains two different but largely equivalent formatting languages is kind of emblematic of its whole design, really.

tip of the iceberg.


I haven't seen anyone share an author-filtering use case yet, so here's a lightly-edited version of my "git mine" alias:

  log --no-merges --date=short --author="cyranix" --stat
This allows me to skim through my own recent changes.

"--no-merges" is included in just about every log invocation I run; in a continuous integration workflow, I generally don't find merge commit info to be all that informative.

As an additional tip, the "-n <count>" form of limiting the history can be shortened to "-<count>". For example, reviewing the diff of the last two commits can be achieved with "git log -p -2".


I use a light variant from it :

  git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit --date-order"


The difference is an added --date-order:

"Show no parents before all of its children are shown, but otherwise show commits in the commit timestamp order."


lol, I named my alias `git lol` because it is logs in one line.


lol, I named mine 'git l' because I type it far too often.


I use two-letter bash aliases for all my most commonly used git commands.

    git status
    git diff
    git diff --cached
    git add -A
    git commit -m Hello
    git push
Is instead just

    st
    dp
    di
    aa
    cm Hello
    pu
Additionally I also have

    le
For

    git shortlog -s -e
which I don’t use very often but often enough that having an alias for it still makes sense


I edited my inputrc to do a prefix search. So I just ‘git x’ where x is some letter, pressing up usually finds me what I want.

It still surprises me we don’t have good bash autocomplete.

Not sure how hard it is to create a shell but i’d do it in a heartbeat.


i think 'xonsh' aims to do that


Mine is only `gl`, but I edited my .zshrc for that.


I named my custom logging command 'git ls', which is an idiotic name (that should list files or something), but I'm stuck with it now :)


mine is assigned to the bash alias "gl"


Many of us at work have the following alias in our .gitconfig file:

lola = log --graph --decorate --pretty=oneline --abbrev-commit --all

This is similar to others posted here.


Have you tried other git UIs (IDE or not) ?

I wonder if there's one that is as good as magit (my opinion is no, but that's why I ask)


gitk 7-8 years ago, Github desktop app few years later. I used version control features in Eclipse and IntelliJ for SVN, but I believe the same interface maps to Git as well.

None of them even compare with Magit. They offer a small subset of Git features - unlike Magit, which gives you almost all of them, + some higher level abstractions (like "merge into"), and you're always one ! ! press away from entering a manual command. Also, the other interfaces I've used were mostly mouse based, whereas Magit just flows. Feels order of magnitude more efficient than anything else.


> you're always one ! ! press away from entering a manual command

Huh, I didn't know this. I'll probably live in Magit from now on.


Also useful: any time you find yourself wondering what did Magit just do, press $ to display raw output from git commands (lists the commands issued and their return codes, TAB expands them to full output).


I don't do it that often but I felt compelled to tip magit maintainer because it's just a beautiful and important piece of my emacs life.


Magit had a Kickstarter recently (yes, an Emacs mode on Kickstarter; I was shocked too), to raise funds for continued development. I dropped some cash there; after all, it helps me quite a lot to earn my paycheck.


is it because Kickstarter is contradictory to FSF mindset ?

I couldn't pay on KS so I asked him his paypal handle, but it was the KS campaign that motivated me. As you said, it's a great asset to the day of developpers (or any document maintainer under git)


I couldn't bare those relative times.

My prefered tool is `tig --all` which gives me a nice view of the repo with its branches.




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

Search: