git log
--raw
--numstat
--shortstat
--dirstat
--summary
--name-only
--name-status
--check
git log --pretty=format:'%C(yellow)%h %Cred%ad %Cblue%an%Cgreen%d %Creset%s' --date=short
Logs in Current Branch
git log
Logs last n number of commits
git log -n 5
Commits between branch1 and branch2
git log branch1..branch2
Commits in branch1 that are not in branch2
git log branch1 ^branch2
Between a Date Range
git log --since="2 weeks ago"
git whatchanged --since="2 weeks ago"
Changes by File
See a list of commits ands changes for a particular file over its history.
git log -p filename.js
Stats and Patches
The following will show statistics about commits and show the patch information as well.
git log --stat -p
search
git log --grep="Change in Commit Message"
git log -S"Change in Source Code""
get current branch
git rev-parse --abbrev-ref HEAD
git branch --show-current
log
git log --pretty=format:'%Cgreen%h %C(yellow)%H %Cred%aD %Cblue%an %Cgreen%aE %Cgreen%d %Creset%s' --date=short
no merge
git log --pretty=format:'%Cgreen%h %C(yellow)%H %Cred%aD %Cblue%an %Cgreen%aE %Cgreen%d %Creset%s' --no-merges --first-parent $(git branch --show-current)
git log --pretty=format:'%Cgreen%h %C(dim white)%H %C(dim white)%aI %ar %Creset%C(bold blue)%an %Creset%C(dim blue)%aE %C(bold red)%d %Creset%C(white)%s' --first-parent $(git branch --show-current)
merge
--merges
Print only merge commits. This is exactly the same as --min-parents=2.
--no-merges
Do not print commits with more than one parent. This is exactly the same as --max-parents=1.
--min-parents=<number>
--max-parents=<number>
--no-min-parents
--no-max-parents
Show only commits which have at least (or at most) that many parent commits. In particular,
--max-parents=1 is the same as --no-merges,
--min-parents=2 is the same as --merges.
--max-parents=0 gives all root commits
--min-parents=3 all octopus merges.
--no-min-parents and --no-max-parents reset these limits (to no limit) again.
Equivalent forms are --min-parents=0 (any commit has 0 or more parents) and --max-parents=-1 (negative numbers denote no upper limit).
branch
--all
Pretend as if all the refs in refs/, along with HEAD, are listed on the command line as <commit>.
--branches[=<pattern>]
Pretend as if all the refs in refs/heads are listed on the command line as <commit>.
If <pattern> is given, limit branches to ones matching given shell glob.
If pattern lacks ?, *, or [, /* at the end is implied.
--tags[=<pattern>]
Pretend as if all the refs in refs/tags are listed on the command line as <commit>.
If <pattern> is given, limit tags to ones matching given shell glob.
If pattern lacks ?, *, or [, /* at the end is implied.
--remotes[=<pattern>]
Pretend as if all the refs in refs/remotes are listed on the command line as <commit>.
If <pattern> is given, limit remote-tracking branches to ones matching given shell glob.
If pattern lacks ?, *, or [, /* at the end is implied.
Search
-L<start>,<end>:<file>
-L:<funcname>:<file>
--grep=<pattern>
Limit the commits output to ones with log message that matches the specified pattern (regular expression).
With more than one --grep=<pattern>, commits whose message matches any of the given patterns are chosen (but see --all-match).
When --notes is in effect, the message from the notes is matched as if it were part of the log message.
--all-match
Limit the commits output to ones that match all given --grep, instead of ones that match at least one.
--invert-grep
Limit the commits output to ones with log message that do not match the pattern specified with --grep=<pattern>.
-i
--regexp-ignore-case
Match the regular expression limiting patterns without regard to letter case.
--basic-regexp
Consider the limiting patterns to be basic regular expressions; this is the default.
-E
--extended-regexp
Consider the limiting patterns to be extended regular expressions instead of the default basic regular expressions.
-F
--fixed-strings
Consider the limiting patterns to be fixed strings (don’t interpret pattern as a regular expression).
-S<string>
Look for differences that change the number of occurrences of the specified string (i.e. addition/deletion) in a file. Intended for the scripter’s use.
It is useful when you’re looking for an exact block of code (like a struct), and want to know the history of that block since it first came into being:
use the feature iteratively to feed the interesting block in the preimage back into -S, and keep going until you get the very first version of the block.
Binary files are searched as well.
-G<regex>
Look for differences whose patch text contains added/removed lines that match <regex>.