Skip to content

Instantly share code, notes, and snippets.

@techforum-repo
Last active February 22, 2021 17:48
Show Gist options
  • Save techforum-repo/92cbe27a54a56c95832a07da773e81d2 to your computer and use it in GitHub Desktop.
Save techforum-repo/92cbe27a54a56c95832a07da773e81d2 to your computer and use it in GitHub Desktop.

Git log command

git log (Lists the commits made in the repository)

git log --reverse (Display the output in reverse)

git log --stat (Show statistics for files modified in each commit)
git log --shortstat (Output only the last line of the --stat format containing total number of modified files, as well as number of added and deleted lines.)

git log --relative-date (Display the date in a relative format e.g. “2 weeks ago”)

git log --graph (Display an ASCII graph of the branch and merge history beside the log output.)
git log --oneline (the commit message is prefixed with this information on the same line)
git log --decorate (Format the ref names of any commits, default value is short,--decorate[=short|full|auto|no] )

git log --abbrev-commit (Show only the first few characters of the SHA-1 checksum instead of all 40)

git log --name-status (Show the list of files affected with added/modified/deleted information as well)

git log -p (Show the patch introduced with each commit)

git log --graph --decorate --oneline (Combine multiple options)

git log -- StyleNameModel.java (Shows the commit that changed the specific file )

git log --follow -- StyleNameModel.java (Shows the commit that changed the specific file, including those commits that occurred before the file was given its present name)

git log -p -- StyleNameModel.java (Show the patch introduced with each commit to a specific file)

git log -L '17,20:StyleNameModel.java' (Shows how the line number between 17 and 20 in the file StyleNameModel.java evolved over time)

git log -L '/public String getStyleNameSite/,/}/':StyleNameModel.java (Shows how the function getStyleNameSite in the file StyleNameModel.java evolved over time)

Format Date

git log --date=relative (Shows dates relative to the current time, e.g. “2 hours ago”)
git log --date=local
git log --date=iso (Shows timestamps in a ISO 8601-like format)
git log --date=iso-strict (Shows timestamps in strict ISO 8601 format)
git log --date=rfc (Shows timestamps in RFC 2822 format)
git log --date=short (Shows only the date, but not the time, in YYYY-MM-DD format)
git log --date=raw
git log --date=human
git log --date=unix (Shows the date as a Unix epoch timestamp - seconds since 1970.)
git log --date=format:'%Y-%m-%d %H:%M:%S' (Custom Date Format)

Commit Limiting

git log -all
git log --merges
git log --no-merges

git log --branches
git log --branches='feature/*'
git log --tags
git log --tags='v1.0*'
git log --remotes

git log --author="Albin Issac" (Only show commits in which the author entry matches the specified string)
git log --committer="Albin Issac" (Only show commits in which the commiter entry matches the specified string)

git log -n 3 (Limit to Last 3(n) commits)

git log --after="2020-2-3" --before="2020-3-19" (Limit the commits to those made after and before the specified date)

git log --author="techforum-repo" --after ="10 days ago" --before ="7 days ago"

git log --author="techforum-repo" --since ="10 days ago" --until ="7 days ago"

git log --grep 'Enable Watch*' (Only show commits with a commit message containing the string)

git log -S 'StyleNameModel' (Only show commits adding or removing code matching the string)

git log feature..master (Only show commits difference between two branches)
git log 396a5e3..d21d7c3 (Only show commits between two commits)

Commit Formatting

git log --pretty=oneline
git log --pretty=short
git log --pretty=medium
git log --pretty=full
git log --pretty=fuller
git log --pretty=email
git log --pretty=raw

git log --pretty=format:"%C(yellow bold)Commit Hash: %H, %C(blue bold)Author: %aN, %C(bold green)Date: %aD ,%C(bold red)Email: %ae"

Shortlog

git shortlog (Summarize git log output)

git shortlog -n (Sort output according to the number of commits per author instead of author alphabetic order.)

git shortlog -s (Suppress commit description and provide a commit count summary only.)

git shortlog -e (Show the email address of each author.)

git shortlog -s -n

Show/Print Specific Commit

git show a158efc
git show --stat a158efc

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