Skip to content

Instantly share code, notes, and snippets.

@jmatsu
Last active August 29, 2015 14:15
Show Gist options
  • Save jmatsu/048fe59fa30d603c2eb2 to your computer and use it in GitHub Desktop.
Save jmatsu/048fe59fa30d603c2eb2 to your computer and use it in GitHub Desktop.
Useful Git command with options when creating automation scripts.

Get current information of XXX

simple log

git log -n 1 This equals to the following command. (Default) git log -n 1 --format="commit %H%x0A\ Author: %an %ae%x0A\ Date: %ad"

commit id

git log -n 1 --format=%h collapsed git log -n 1 --format=%H expanded

tree id

git log -n 1 --format=%t collapsed git log -n 1 --format=%T expanded

parents id

git log -n 1 --format=%p collapsed git log -n 1 --format=%P expanded

commit subject

git log -n 1 --format=%s

author name

git log -n 1 --format=%an

author email

git log -n 1 --format=%ae

author date

git log -n 1 --format=%ad

committer name

git log -n 1 --format=%cn

committer email

git log -n 1 --format=%ce

committer date

git log -n 1 --format=%cd

branch name

git rev-parse --abbrev-ref @

refs

git rev-parse --symbolic-full-name @

Get filtered results

Branch list contain such commit

git branch --contains=$commit_id

Show textual logs

Word-diff (not line-diff)

git diff --word-diff

Word-diff specific separater

git diff --word-diff-regex="[^[:blank:],]" (this sample separates by space and canma.)

commit ids

git log --format=%H

commit subjects

git log --format=%s

Useful for creating tree-graph (csv)

git log --format="%H,%T,%P"

Useful for communication of developers and branch behaviors (JSON)

git log --format='{"commit_id":"%H","tree_id":"%T","parents_ids":"%P","Author":{"name":"%an","email":"%ae","Date":"%ad"}, "Committer":{"name":"%cn","email":"%ce","Date":"%cd"}}'

Visualization of logs

Simple graph

git log --graph --oneline --decorate

Recommended aliases (others)

one log (e.g git olog)

olog = log -n 1

one log with format (e.g git ologf "%H %s")

ologf = log -n 1 --format=

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment