Rarely handy Git commands

Compare two branches/tags

This command will compare two branches/commits/tags/hashes (anything really) and will output a one-line-per-commit-nicely-formatted log

$ git log --decorate --date=relative --format=format:"%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)[%an]%C(reset)%C(bold yellow)%d%C(reset)" origin/master..HEAD

Thanks to the origin/master..HEAD at the end, this will show any commits on your local branch which are not on your remote. Change this to whatever suits you - make sure there are two dots between the two.

See a diff without whitespace

I have my editor to trim trailing spaces - if I open an old file and press save, it removes a space from (pretty much) every line. This can be messy when viewing a git diff. With the following command, you can git diff while ignoring whitespace

$ git diff --ignore-space-at-eol -b -w --ignore-blank-lines

Git log with a graph

There may be times you wish to show a git log with a pretty graph on the command line, to work out where branches have split and merged

$ git log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold cyan)%aD%C(reset) %C(bold green)(%ar)%C(reset)%C(bold yellow)%d%C(reset)%n''%C(white)%s%C(reset) %C(dim white)- %an%C(reset)' --all

Show today's commits

You may wish to see what commits you have done today (especially handy if you work in a team)

$ git log --since=1am --author='Mike Street' --format='- %s'

Don't forget to change the author to your name

Delete all git tags

To delete all the git tags:

Locally

$ git tag | xargs git tag -d

Remotely

$ git tag -l | xargs -n 1 git push --delete origin
This website is currently having a full content audit - apologies if some of the code or content looks a bit funky!

View this post on Gitlab

You might also enjoy…

  • Render Conf 30th March 2017 - A review

    Posted on 18th May 2017. Written For Liquid Light

    On 30th March, I took the many trains over the many hours required to get to Oxford from Brighton and attended Render Conf. In it’s second year, this conference ...

  • HTML 5 collapsable information - works in a Github/Gitlab issue

    Posted on 10th May 2017.

    It may be that you wish to include a lot of information in a Github issue (or anywhere else on the web that allows HTML) but don't want the code/error to fill out the page. Luckily, there is a way to collapse it using latest HTML tags.

Mike Street

Written by Mike Street

Mike is a front-end developer from Brighton, UK. He spends his time writing, cycling and coding. You can find Mike on Twitter.