GIT-LOG(1)
๐ GIT-LOG(1) ๐ โ the Git Manual page, bestie ๐
๐ธ NAME ๐ธ
git-log โ show commit logs. ๐
โจ SYNOPSIS โจ
git log [<options>] [<revision-range>] [[--] <path>...]
๐ DESCRIPTION ๐
Okay so bestie, git log shows the commit logs. Thatโs the whole assignment. ๐
It lists commits that are reachable by following the parent links from the commit(s) you give it, but it excludes commits that are reachable from the one(s) that have a ^ in front of them. By default, the output comes in reverse chronological order, no cap. โณ
You can think of this as a set operation, fr fr. Commits reachable from any of the commits given on the command line form a set, and then commits reachable from any of the ones given with ^ in front are subtracted from that set. The remaining commits are what comes out in the commandโs output. Various other options and paths parameters can be used to further limit the result. ๐ซถ
So the following command:
$ git log foo bar ^baz
means "list all the commits which are reachable from foo or bar, but not from baz". Periodt.
A special notation, <commit1>..<commit2>, can be used as a short-hand for ^<commit1> <commit2>. For example, either of the following may be used interchangeably:
$ git log origin..HEAD
$ git log HEAD ^origin
Another special notation is <commit1>...<commit2>, which is useful for merges. The resulting set of commits is the symmetric difference between the two operands. The following two commands are equivalent:
$ git log A B --not $(git merge-base --all A B)
$ git log A...B
The command takes options applicable to the git-rev-list(1) command to control what is shown and how, and options applicable to the git-diff(1) command to control how the changes each commit introduces are shown. ๐
๐ OPTIONS ๐
--followโ Continue listing the history of a file beyond renames (works only for a single file). Bestie, single file only โ thatโs the rule. ๐--no-decorate,--decorate[=(short|full|auto|no)]โ Print out the ref names of any commits that are shown. The option--decorateis short-hand for--decorate=short. Default to the configuration value oflog.decorateif configured, otherwise,auto. Possible values are:shortโ the ref name prefixesrefs/heads/,refs/tags/andrefs/remotes/are not printed.fullโ the full ref name (including prefix) is printed.autoโ if the output is going to a terminal, the ref names are shown as ifshortwere given, otherwise no ref names are shown. โจ
--decorate-refs=<pattern>,--decorate-refs-exclude=<pattern>โ For each candidate reference, do not use it for decoration if it matches any of the<pattern>parameters given to--decorate-refs-excludeor if it doesnโt match any of the<pattern>parameters given to--decorate-refs. Thelog.excludeDecorationconfig option allows excluding refs from the decorations, but an explicit--decorate-refspattern will override a match inlog.excludeDecoration. If none of these options or config settings are given, then references are used as decoration if they matchHEAD,refs/heads/,refs/remotes/,refs/stash/, orrefs/tags/. ๐ฆ--clear-decorationsโ When specified, this option clears all previous--decorate-refsor--decorate-refs-excludeoptions and relaxes the default decoration filter to include all references. This option is assumed if the config valuelog.initialDecorationSetis set toall. ๐--sourceโ Print out the ref name given on the command line by which each commit was reached. Iconic. ๐--mailmap,--no-mailmap,--use-mailmap,--no-use-mailmapโ Use mailmap file to map author and committer names and email addresses to canonical real names and email addresses. Seegit-shortlog(1). ๐ซถ--full-diffโ The way that--full-diffworks: without this flag,git log -p <path>...shows commits that touch the specified paths, and diffs about the same specified paths. With this, the full diff is shown for commits that touch the specified paths; this means that"<path>..."limits only commits, and doesnโt limit diff for those commits. Note that this affects all diff-based output types, e.g. those produced by--stat, etc. ๐ฅ--log-sizeโ Include a linelog size <number>in the output for each commit, where<number>is the length of that commitโs message in bytes. Itโs literally intended to speed up tools that read log messages fromgit logoutput by allowing them to allocate space in advance. โก-L<start>,<end>:<file>,-L:<funcname>:<file>โ Trace the evolution of the line range given by<start>,<end>, or by the function name regex<funcname>, within the<file>. You may not give any pathspec limiters, iykyk. ๐ This is currently limited to a walk starting from a single revision, i.e., you may only give zero or one positive revision arguments, and<start>and<end>(or<funcname>) must exist in the starting revision. You can specify this option more than once. Implies--patch. Patch output can be suppressed using--no-patch. Non-patch diff formats--raw,--name-only,--name-status, and--summaryare supported. Diff stat formats (--stat,--numstat,--shortstat,--dirstat) are not currently implemented. Patch formatting options such as--word-diff,--color-moved,--no-prefix, and whitespace options (-w,-b) are supported, as are pickaxe options (-S,-G) and--diff-filter.<start>and<end>can take one of these forms:<number>โ If<start>or<end>is a number, it specifies an absolute line number (lines count from 1)./<regex>/โ This form will use the first line matching the given POSIX<regex>. If<start>is a regex, it will search from the end of the previous-Lrange, if any, otherwise from the start of file. If<start>is^/<regex>/, it will search from the start of file. If<end>is a regex, it will search starting at the line given by<start>.+<offset>or-<offset>โ This is only valid for<end>and will specify a number of lines before or after the line given by<start>.:<funcname>โ If given in place of<start>and<end>, it is a regular expression that denotes the range from the first funcname line that matches<funcname>, up to the next funcname line.:<funcname>searches from the end of the previous-Lrange, if any, otherwise from the start of file.^:<funcname>searches from the start of file. The function names are determined in the same way asgit diffworks out patch hunk headers (see Defining a custom hunk-header ingitattributes(5)). ๐ง
<revision-range>โ Show only commits in the specified revision range. When no<revision-range>is specified, it defaults toHEADโ main character energy, i.e. the whole history leading to the current commit.origin..HEADspecifies all the commits reachable from the current commit (i.e.HEAD), but not fromorigin. For a complete list of ways to spell<revision-range>, see the Specifying Ranges section ofgitrevisions(7). ๐[--] <path>...โ Show only commits that are enough to explain how the files that match the specified paths came to be. See History Simplification below for details and other simplification modes. Paths may need to be prefixed with--to separate them from options or the revision range, when confusion arises. ๐ซ
๐ฆ Commit Limiting ๐ฆ
Besides specifying a range of commits that should be listed using the special notations explained in the description, additional commit limiting may be applied. ๐
Vibe check: using more options generally further limits the output (e.g. --since=<date1> limits to commits newer than <date1>, and using it with --grep=<pattern> further limits to commits whose log message has a line that matches <pattern>), unless otherwise noted. ๐
Note that these are applied before commit ordering and formatting options, such as --reverse. ๐
-<number>,-n <number>,--max-count=<number>โ Limit the output to the first<number>commits that would be shown. โญ--max-count-oldest=<number>โ Limit the output to the last<number>commits that would be shown. ๐--skip=<number>โ Skip<number>commits before starting to show the commit output. ๐ฆ--since=<date>,--after=<date>โ Show commits more recent than<date>. As a special case,todaymeans the last midnight. โฐ--since-as-filter=<date>โ Show all commits more recent than<date>. This visits all commits in the range, rather than stopping at the first commit which is older than<date>. ๐--until=<date>,--before=<date>โ Show commits older than<date>. ๐ฐ๏ธ--author=<pattern>,--committer=<pattern>โ Limit the commits output to ones with author/committer header lines that match the<pattern>regular expression. With more than one--author=<pattern>, commits whose author matches any of the<pattern>are chosen (similarly for multiple--committer=<pattern>). โจ--grep-reflog=<pattern>โ Limit the commits output to ones with reflog entries that match the<pattern>regular expression. With more than one--grep-reflog, commits whose reflog message matches any of the given patterns are chosen. It is an error to use this option unless--walk-reflogsis in use. ๐จ--grep=<pattern>โ Limit the commits output to ones with a log message that matches the<pattern>regular expression. With more than one--grep=<pattern>, commits whose message matches any of the<pattern>are chosen (but see--all-match). When--notesis in effect, lowkey 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 a 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). ๐-P,--perl-regexpโ Consider the limiting patterns to be Perl-compatible regular expressions. Support for these types of regular expressions is an optional compile-time dependency. If Git wasnโt compiled with support for them, providing this option will cause it to die. ๐--remove-emptyโ dips out the moment a path stops existing in the tree. gone = stop โ--mergesโ only merge commits, nothing else. literally identical to--min-parents=2, no cap ๐ซถ--no-mergesโ the opposite vibe: hide anything with more than one parent. exactly the same as--max-parents=1๐--min-parents=<number>,--max-parents=<number>,--no-min-parents,--no-max-parentsโ filter by how many parents a commit has, at least or at most. so--max-parents=1=--no-merges,--min-parents=2=--merges. and bestie,--max-parents=0hands you all the root commits, while--min-parents=3gives you every octopus merge ๐ (iconic behaviour honestly)
--no-min-parents and --no-max-parents reset those limits back to no-limit. the equivalent forms are --min-parents=0 (any commit has 0 or more parents) and --max-parents=-1 (negative numbers = no upper limit, yes really).
--first-parentโ when it's picking commits to include, it only follows the first parent once it hits a merge commit. this is lowkey the best overview when you're watching one topic branch evolve, because merges into a topic branch are usually just "adjusting to the updated upstream" โ so this lets you ignore all the individual commits that merge dragged into your history โจ
heads up though: this also changes the default diff format for merge commits to first-parent, see --diff-merges=first-parent for the deets.
--exclude-first-parent-onlyโ same energy but for the excluding side: when finding commits to exclude (with a^), follow only the first parent on a merge commit. great for finding the set of changes in a topic branch from the point where it diverged from the remote branch, given that arbitrary merges can be valid topic branch changes ๐--maximal-onlyโ restricts the output commits to only those that are not reachable from any other commits in the revision range. main character commits only ๐--notโ flips the meaning of the^prefix (or the lack of it) for every revision specifier that follows, right up until the next--not. and there's a lil subtlety: if you use it on the command line before--stdin, the revisions coming through stdin won't be affected by it. conversely, if you pass it via standard input, the revisions on the command line won't be affected by it. they don't share ๐ซถ--allโ pretend every ref inrefs/, plusHEAD, was listed on the command line as<commit>๐--branches[=<pattern>]โ pretend all the refs inrefs/headsgot listed as<commit>. give it a<pattern>and it limits branches to ones matching that shell glob โ and if your pattern has no?,*, or[, then/*at the end is implied ๐--tags[=<pattern>]โ same deal but forrefs/tags.<pattern>limits tags to the ones matching that shell glob, and again, if the pattern lacks?,*, or[, then/*at the end is implied ๐--remotes[=<pattern>]โ you already know: pretend all refs inrefs/remotesare on the command line as<commit>.<pattern>limits remote-tracking branches by shell glob, and if the pattern lacks?,*, or[, then/*at the end is implied ๐--glob=<glob-pattern>โ pretend every ref matching the shell glob<glob-pattern>was listed as<commit>. a leadingrefs/gets auto-prepended if you forgot it. no?,*, or[in your pattern? then/*at the end is implied, periodt โญ--exclude=<glob-pattern>โ nope, don't include refs matching<glob-pattern>that the next--all,--branches,--tags,--remotes, or--globwould've otherwise considered. repeating this option stacks up exclusion patterns until the next--all,--branches,--tags,--remotes, or--globโ other options or arguments do not clear the pile ๐
real talk on the patterns: they should not begin withrefs/heads,refs/tags, orrefs/remoteswhen you're applying them to--branches,--tags, or--remotesrespectively, and they must begin withrefs/when applied to--globor--all. and if you want a trailing/*, you have to write it out explicitly. no vibes-based inference here.
--exclude-hidden=(fetch|receive|uploadpack)โ skip refs thatgit-fetch,git-receive-packorgit-upload-packwould hide, by consulting the matchingfetch.hideRefs,receive.hideRefsoruploadpack.hideRefsconfig along withtransfer.hideRefs(seegit-config(1)). this one affects the next pseudo-ref option,--allor--glob, and it's cleared after they're processed ๐ง--reflogโ pretend every object mentioned by reflogs was listed on the command line as<commit>๐ธ--alternate-refsโ pretend all objects mentioned as ref tips of alternate repositories got listed on the command line. an alternate repository is any repository whose object directory is specified inobjects/info/alternates. heads up: the set of included objects may be modified bycore.alternateRefsCommand, etc. โ seegit-config(1)๐ฆ--single-worktreeโ by default, when you've got more than one working tree (seegit-worktree(1)), these options examine all of them:--all,--reflogand--indexed-objects. this flag forces them to look at the current working tree only ๐--ignore-missingโ sees an invalid object name in the input? pretends the bad input was never given. gaslight, gatekeep, girlboss ๐ญ--bisectโ pretend the bad bisection refrefs/bisect/badwas listed, and as if it was followed by--notand the good bisection refsrefs/bisect/good-*on the command line ๐ฅ--stdinโ on top of getting arguments from the command line, read them from standard input too. accepts commits and pseudo-options like--alland--glob=. when a--separator shows up, the input after it is treated as paths and used to limit the result. and ngl the scoping rules matter: flags like--notread via standard input are only respected for arguments passed the same way, and will not influence any subsequent command line arguments ๐ซถ--cherry-markโ like--cherry-pick(below) but it marks equivalent commits with=instead of omitting them, and inequivalent ones with+โจ--cherry-pickโ omits any commit that introduces the same change as another commit on the "other side", when the set of commits is limited with symmetric difference. example time: if you have two branches,AandB, the usual way to list all commits on only one side is--left-right(see the example below in the description of the--left-rightoption). but that still shows commits that were cherry-picked from the other branch (like, "3rd on b" may be cherry-picked from branchA). with this option, those pairs of commits get excluded from the output ๐--left-only,--right-onlyโ list only commits on the respective side of a symmetric difference, i.e. only those that--left-rightwould mark<resp.>respectively.
for example, --cherry-pick --right-only A...B omits those commits from B which are in A or are patch-equivalent to a commit in A. in other words, this lists the + commits from git cherry A B. more precisely, --cherry-pick --right-only --no-merges gives the exact list ๐
--cherryโ a synonym for--right-only --cherry-mark --no-merges. useful for limiting output to the commits on our side and marking the ones that have been applied to the other side of a forked history, likegit log --cherry upstream...mybranch, similar togit cherry upstream mybranch๐-g,--walk-reflogsโ instead of walking the commit ancestry chain, walk reflog entries from most recent to older ones. but bestie, when you use this you cannot specify commits to exclude โ that means^<commit>,<commit1>..<commit2>, and<commit1>...<commit2>notations are straight-up off the table ๐ซ
with --pretty formats other than oneline and reference (for obvious reasons), this gives you two extra lines of info pulled from the reflog. the reflog designator in the output may show as ref@{<Nth>} (where <Nth> is the reverse-chronological index in the reflog) or as ref@{<timestamp>} (with the <timestamp> for that entry), depending on a few rules:
- If the starting point is specified as
ref@{<Nth>}, show the index format. - If the starting point was specified as
ref@{now}, show the timestamp format. - If neither was used, but
--datewas given on the command line, show the timestamp in the format requested by--date. - Otherwise, show the index format.
under --pretty=oneline, the commit message is prefixed with this information on the same line. and this option cannot be combined with --reverse โ that combo is a no ๐. see also git-reflog(1).
under --pretty=reference, this information will not be shown at all ๐
--mergeโ shows commits touching conflicted paths in the rangeHEAD...<other>, where<other>is the first existing pseudoref inMERGE_HEAD,CHERRY_PICK_HEAD,REVERT_HEADorREBASE_HEAD. only works when the index has unmerged entries. this is the one for showing relevant commits while you're resolving conflicts from a 3-way merge ๐ฅ--boundaryโ outputs excluded boundary commits. boundary commits are prefixed with-โญ
๐ธ HISTORY SIMPLIFICATION ๐ธ
sometimes you only care about parts of the history โ like, the commits touching one particular <path>. but there are two parts to History Simplification, bestie: one part is selecting the commits, and the other part is how to do it, because there are various strategies to simplify the history ๐ฆ
the following options select the commits to be shown:
<paths>โ commits modifying the given<paths>are selected.--simplify-by-decorationโ commits that are referred to by some branch or tag are selected.
note that extra commits can be shown to give a meaningful history โ that's by design, don't @ it ๐
the following options affect the way the simplification is performed:
Default mode
simplifies the history to the simplest history explaining the final state of the tree. simplest because it prunes some side branches if the end result is the same (i.e. merging branches with the same content) โจ
--show-pulls
includes all commits from the default mode, but also any merge commits that are not TREESAME to the first parent but are TREESAME to a later parent. this mode is helpful for showing the merge commits that "first introduced" a change to a branch ๐
--full-history
same as the default mode, but it does not prune some history. that's the whole difference, no cap ๐ซถ
--denseโ only the commits you actually picked show up, plus a few extras so the history still makes sense. basically the "keep it cute, keep it minimal" setting โจ--sparseโ every commit in the simplified history gets shown. no filtering, no hiding, all of them ๐--simplify-mergesโ this is an add-on to--full-history, and what it does is prune away merges that are genuinely pointless, because no selected commit actually contributes anything to that merge. bye bye clutter ๐งน- **
--ancestry-path[=<commit>]** โ okay so, when you're looking at a range of commits (like<commit1>..<commit2>or<commit2> ^<commit1>) and there's a commit<commit>inside that range, this only shows you commits in the range that are ancestors of<commit>, descendants of<commit>, or<commit>itself. if you don't name a commit, it uses<commit1>(the excluded side of the range) as<commit>`. you can pass it multiple times too โ and if you do, a commit gets included if it's any one of the commits you gave, or an ancestor or descendant of any one of them ๐ฆ
๐ธ a more detailed explanation follows (grab a snack bestie)
So suppose you specified foo as the <paths>. Commits that modify foo? We're calling those !TREESAME. Everything else is TREESAME. (In a diff filtered for foo, they look different and equal, respectively. that's literally the whole bit ๐)
In everything below, we're always referring to the same example history, so you can actually see the difference between the simplification settings. We're assuming you're filtering for a file foo in this commit graph:
.-A---M---N---O---P---Q
/ / / / / /
I B C D E Y
\ / / / / /
`-------------' X
The horizontal line of history A---Q is taken to be the first parent of each merge. And the commits are:
Iis the initial commit โfooexists in it with contentsasdf, and a filequuxexists with contentsquux. Initial commits get compared to an empty tree, soIis !TREESAME ๐- In
A,foocontains justfoo. Bcontains the same change asA. Its mergeMis trivial and hence TREESAME to all parents.Cdoes not changefoo, but its mergeNchanges it tofoobar, so it is not TREESAME to any parent.Dsetsfootobaz. Its mergeOcombines the strings fromNandDtofoobarbaz; i.e., it is not TREESAME to any parent.Echangesquuxtoxyzzy, and its mergePcombines the strings toquux xyzzy.Pis TREESAME toO, but not toE.Xis an independent root commit that added a new fileside, andYmodified it.Yis TREESAME toX. Its mergeQaddedsidetoP, andQis TREESAME toP, but not toY.
So rev-list walks backwards through history, including or excluding commits depending on whether --full-history and/or parent rewriting (via --parents or --children) are used. Here are the settings available to you ๐
Default mode
Commits are included if they're not TREESAME to any parent (though this can be changed โ see --sparse below). If the commit was a merge, and it was TREESAME to one parent, follow only that parent. (Even if there are several TREESAME parents, follow only one of them.) Otherwise, follow all parents.
Which results in:
.-A---N---O
/ / /
I---------D
Notice how that rule โ only follow the TREESAME parent if one's available โ removed B from consideration entirely. C was considered via N, but is TREESAME. Root commits are compared to an empty tree, so I is !TREESAME.
Parent/child relations are only visible with --parents, but that doesn't affect which commits get selected in default mode, so we've shown the parent lines anyway ๐ซถ
--full-history without parent rewriting
This mode differs from the default in exactly one way: it always follows all parents of a merge, even if it's TREESAME to one of them. And even if more than one side of the merge has commits that are included, that does not mean the merge itself is included! In the example, we get:
I A B N D O P Q
M was excluded because it's TREESAME to both parents. E, C and B were all walked, but only B was !TREESAME, so the others don't appear.
ngl, without parent rewriting it's not really possible to talk about the parent/child relationships between the commits, so we show them disconnected. it's giving scattered ๐ญ
--full-history with parent rewriting
Ordinary commits are only included if they're !TREESAME (though, again, this can be changed โ see --sparse below).
Merges are always included. But their parent list gets rewritten: along each parent, prune away commits that aren't included themselves. That gives us:
.-A---M---N---O---P---Q
/ / / / /
I B / D /
\ / / / /
`-------------'
Compare that to --full-history without rewriting up above. Note that E was pruned away because it's TREESAME, but the parent list of P was rewritten to contain E's parent I. Same thing happened for C and N, and for X, Y and Q. iconic behavior honestly โจ
On top of all the settings above, you can also change whether TREESAME affects inclusion:
--denseโ commits that are walked are included if they're not TREESAME to any parent.--sparseโ all commits that are walked are included.
heads up bestie: without --full-history, this still simplifies merges โ if one of the parents is TREESAME, we follow only that one, so the other sides of the merge are never walked at all ๐ฆ
--simplify-mergesโ first, build a history graph the same way--full-historywith parent rewriting does (see above). Then simplify each commitCto its replacementC'in the final history, according to these rules:- Set
C'toC. - Replace each parent
PofC'with its simplificationP'. In the process, drop parents that are ancestors of other parents or that are root commits TREESAME to an empty tree, and remove duplicates โ but take care to never drop all parents that we are TREESAME to. - If after this parent rewriting,
C'is a root or merge commit (has zero or >1 parents), a boundary commit, or !TREESAME, it remains. Otherwise, it's replaced with its only parent.
- Set
The effect of this is best shown by comparing to --full-history with parent rewriting. The example turns into:
.-A---M---N---O
/ / /
I B D
\ / /
`---------'
Note the major differences in N, P, and Q over --full-history:
N's parent list hadIremoved, because it's an ancestor of the other parentM. Still,Nremained because it's !TREESAME.P's parent list similarly hadIremoved.Pwas then removed completely, because it had one parent and is TREESAME.Q's parent list hadYsimplified toX.Xwas then removed, because it was a TREESAME root.Qwas then removed completely, because it had one parent and is TREESAME.
There's another simplification mode available too:
--ancestry-path[=<commit>]โ limit the displayed commits to those which are an ancestor of<commit>, or which are a descendant of<commit>, or are<commit>itself. ๐
As an example use case, consider this commit history:
D---E-------F
/ \ \
B---C---G---H---I---J
/ \
A-------K---------------L--M
A regular D..M computes the set of commits that are ancestors of M, but excludes the ones that are ancestors of D. That's useful for seeing what happened to the history leading to M since D โ in the sense of "what does M have that didn't exist in D". The result in this example would be all the commits, except A and B (and D itself, obviously).
But when we want to find out which commits in M are contaminated with the bug introduced by D and need fixing, we might want to view only the subset of D..M that are actually descendants of D โ i.e. excluding C and K. That is exactly what the --ancestry-path option does. Applied to the D..M range, it results in:
E-------F
\ \
G---H---I---J
\
L--M
We can also use --ancestry-path=D instead of --ancestry-path โ it means the same thing when applied to the D..M range, it's just more explicit about it ๐
If instead we're interested in a given topic within this range, and all the commits affected by that topic, we might only want to view the subset of D..M which contain that topic in their ancestry path. So using --ancestry-path=H D..M for example would result in:
E
\
C---G---H---I---J
\
L--M
Whereas --ancestry-path=K D..M would result in:
K---------------L--M
Okay so before we talk about another option, --show-pulls, we need to create a new example history. ๐ง
A common problem users face when looking at simplified history is that a commit they know changed a file somehow just... doesn't appear in the file's simplified history. Let's demonstrate with a new example and show how options like --full-history and --simplify-merges work in that case:
.-A---M-----C--N---O---P
/ / \ \ \/ / /
I B \ R-'`-Z' /
\ / \/ /
\ / /\ /
`---X--' `---Y--'
For this example, suppose I created file.txt, which was modified by A, B, and X in different ways. The single-parent commits C, Z, and Y do not change file.txt. The merge commit M was created by resolving the merge conflict to include both changes from A and B, and hence is not TREESAME to either. The merge commit R, however, was created by ignoring the contents of file.txt at M and taking only the contents of file.txt at X. Hence, R is TREESAME to X but not M. Finally, the natural merge resolution to create N is to take the contents of file.txt at R, so N is TREESAME to R but not C. The merge commits O and P are TREESAME to their first parents, but not to their second parents, Z and Y respectively.
When using the default mode, N and R both have a TREESAME parent, so those edges get walked and the others get ignored. The resulting history graph is:
I---X
Okay so when you're on --full-history, Git literally walks every single edge โ no skipping, no shortcuts. This is gonna find you commits A and B and that merge M, but it also drags the merge commits O and P out into the light. With parent rewriting on, the resulting graph is giving:
.-A---M--------N---O---P
/ / \ \ \/ / /
I B \ R-'`--' /
\ / \/ /
\ / /\ /
`---X--' `------'
And here's the tea: those merge commits O and P are pure noise, bestie. They did not actually contribute a change to file.txt. All they did was merge a topic that was based on an older version of file.txt โ that's it, that's the whole contribution. ๐ญ This is lowkey a super common issue in repos using a workflow where tons of contributors work in parallel and merge their topic branches along a single trunk, and the result is that many unrelated merges pop up in your --full-history results. Annoying? A little.
Now when you hit it with the --simplify-merges option, commits O and P just... vanish from the results. ๐
Why? Because the rewritten second parents of O and P are reachable from their first parents. Those edges get removed, and then the commits look like single-parent commits that are TREESAME to their parent. Same thing happens to commit N, so your history view ends up like this:
.-A---M--.
/ / \
I B R
\ / /
\ / /
`---X--'
In this view we're seeing all the important single-parent changes from A, B, and X โ slay โ plus the carefully-resolved merge M and the not-so-carefully-resolved merge R. ๐ This is usually enough info to figure out why commits A and B "disappeared" from history in the default view. But bestie, there are a couple of issues with this approach, and I'm not gonna gatekeep them.
The first issue is performance. Unlike literally any previous option, the --simplify-merges option requires walking the entire commit history before it returns even a single result. So like, yeah, this can make the option difficult to use for very large repositories. ๐ฌ Plan accordingly.
The second issue is one of auditing. When lots of contributors are working on the same repository, it highkey matters which merge commits introduced a change into an important branch. That problematic merge R above? It's not likely to be the merge commit that was actually used to merge into an important branch. Instead, the merge N was the one used to merge R and X into the important branch. And that commit might have info in its commit message about why the change X came to override the changes from A and B. iykyk โ commit messages are lore.
--show-pullsโ so on top of the commits shown in the default history, this shows each merge commit that is not TREESAME to its first parent but is TREESAME to a later parent. ๐ซถ
When a merge commit gets included by --show-pulls, the merge is treated as if it "pulled" the change from another branch. When you use --show-pulls on this example (and no other options), the resulting graph is:
I---X---R---N
Here, the merge commits R and N are included because they pulled the commits X and R into the base branch, respectively. These merges are literally the reason the commits A and B don't appear in the default history. ๐ฅ
When --show-pulls is paired with --simplify-merges, the graph includes all of the necessary info:
.-A---M--. N
/ / \ /
I B R
\ / /
\ / /
`---X--'
Notice that since M is reachable from R, the edge from N to M was simplified away. But N still appears in the history as an important commit because it "pulled" the change R into the main branch. Iconic behavior honestly.
The --simplify-by-decoration option lets you view only the big picture of the topology of the history, by omitting commits that are not referenced by tags. โจ Commits are marked as !TREESAME (in other words, kept after history simplification rules described above) if (1) they are referenced by tags, or (2) they change the contents of the paths given on the command line. All other commits are marked as TREESAME (subject to be simplified away). Simple as that, bestie.
๐ธ Commit Ordering ๐ธ
By default, the commits are shown in reverse chronological order. Classic.
--date-orderโ show no parents before all of its children are shown, but otherwise show commits in the commit timestamp order. โฐ--author-date-orderโ show no parents before all of its children are shown, but otherwise show commits in the author timestamp order. โ๏ธ--topo-orderโ show no parents before all of its children are shown, and avoid showing commits on multiple lines of history intermixed. This one's the neat freak of the group.
For example, in a commit history like this:
---1----2----4----7
\ \
3----5----6----8---
where the numbers denote the order of commit timestamps, git rev-list and friends with --date-order show the commits in the timestamp order: 8 7 6 5 4 3 2 1.
With --topo-order, they would show 8 6 5 3 7 4 2 1 (or 8 7 4 2 6 5 3 1); some older commits are shown before newer ones in order to avoid showing the commits from two parallel development tracks mixed together. ๐
--reverseโ output the commits chosen to be shown (see Commit Limiting section above) in reverse order. Cannot be combined with--walk-reflogs. ๐ซ
๐ฆ Object Traversal ๐ฆ
These options are mostly targeted for packing of Git repositories. Very much a "behind the scenes" moment, but we respect them.
--no-walk[=(sorted|unsorted)]โ only show the given commits, but do not traverse their ancestors. This has no effect if a range is specified. If the argumentunsortedis given, the commits are shown in the order they were given on the command line. Otherwise (ifsortedor no argument was given), the commits are shown in reverse chronological order by commit time. Cannot be combined with--graph. ๐--do-walkโ overrides a previous--no-walk. That's it. That's the whole thing. ๐
๐ Commit Formatting ๐
--pretty[=<format>],--format=<format>โ pretty-print the contents of the commit logs in a given format, where<format>can be one ofoneline,short,medium,full,fuller,reference,email,raw,format:<string>andtformat:<string>. When<format>is none of the above, and has%<placeholder>in it, it acts as if--pretty=tformat:<format>were given. ๐คฏ
See the "PRETTY FORMATS" section for some additional details for each format. When the =<format> part is omitted, it defaults to medium.
Note: you can specify the default pretty format in the repository configuration (see git-config(1)). ๐ซถ
--abbrev-commitโ instead of showing the full 40-byte hexadecimal commit object name, show a prefix that names the object uniquely.--abbrev=<n>(which also modifies diff output, if it is displayed) option can be used to specify the minimum length of the prefix.
This should make --pretty=oneline a whole lot more readable for people using 80-column terminals. ๐
--no-abbrev-commitโ show the full 40-byte hexadecimal commit object name. This negates--abbrev-commit, either explicit or implied by other options such as--oneline. It also overrides thelog.abbrevCommitvariable. ๐ฅ--onelineโ this is a shorthand for--pretty=oneline --abbrev-commitused together. Short and sweet.--encoding=<encoding>โ commit objects record the character encoding used for the log message in their encoding header; this option can be used to tell the command to re-code the commit log message in the encoding preferred by the user. For non plumbing commands this defaults toUTF-8. Note that if an object claims to be encoded in X and we are outputting in X, we will output the object verbatim; this means that invalid sequences in the original commit may be copied to the output. Likewise, ificonv(3)fails to convert the commit, we will quietly output the original object verbatim. ๐ So like, no error, just vibes.--expand-tabs=<n>,--expand-tabs,--no-expand-tabsโ perform a tab expansion (replace each tab with enough spaces to fill to the next display column that is a multiple of<n>) in the log message before showing it in the output.--expand-tabsis a short-hand for--expand-tabs=8, and--no-expand-tabsis a short-hand for--expand-tabs=0, which disables tab expansion.
By default, tabs are expanded in pretty formats that indent the log message by 4 spaces (i.e. medium, which is the default, full, and fuller). ๐ง
--notes[=<ref>]โ show the notes (seegit-notes(1)) that annotate the commit, when showing the commit log message. This is the default forgit log,git showandgit whatchangedcommands when there is no--pretty,--format, or--onelineoption given on the command line.
By default, the notes shown are from the notes refs listed in the core.notesRef and notes.displayRef variables (or corresponding environment overrides). See git-config(1) for more details.
With an optional <ref> argument, use the ref to find the notes to display. The ref can specify the full refname when it begins with refs/notes/; when it begins with notes/, refs/ and otherwise refs/notes/ is prefixed to form the full name of the ref.
Multiple --notes options can be combined to control which notes are being displayed. Examples: "--notes=foo" will show only notes from refs/notes/foo; "--notes=foo --notes" will show both notes from "refs/notes/foo" and from the default notes ref(s). ๐
--no-notesโ do not show notes. This negates the above--notesoption, by resetting the list of notes refs from which notes are shown. Options are parsed in the order given on the command line, so e.g."--notes --notes=foo --no-notes --notes=bar"will only show notes fromrefs/notes/bar. Order matters, bestie! ๐ฏ--show-notes-by-defaultโ show the default notes unless options for displaying specific notes are given. ๐ธ--show-notes[=<ref>],--standard-notes,--no-standard-notesโ these options are deprecated. โ ๏ธ Use the above--notes/--no-notesoptions instead.--show-signatureโ check the validity of a signed commit object by passing the signature togpg --verifyand show the output. ๐--relative-dateโ synonym for--date=relative. That's the whole description, no cap.--date=<format>โ only takes effect for dates shown in human-readable format, such as when using--pretty. Thelog.dateconfig variable sets a default value for the log command's--dateoption. By default, dates are shown in the original time zone (either committer's or author's). If-localis appended to the format (e.g.,iso-local), the user's local time zone is used instead. ๐--date=relativeโ shows dates relative to right now, like2 hours ago. Heads up bestie: the-localoption does nothing here, zero effect, don't come for me.--date=localโ literally just an alias for--date=default-local. That's it. That's the whole vibe.--date=iso(or--date=iso8601) โ timestamps in an ISO 8601-like format. It's giving ISO but it's not fully committed ๐ญ the differences from strict ISO 8601 are:- a space instead of the
Tdate/time delimiter - a space between time and time zone
- no colon between hours and minutes of the time zone
- a space instead of the
--date=iso-strict(or--date=iso8601-strict) โ now this one is strict ISO 8601, no cap. Full commitment.--date=rfc(or--date=rfc2822) โ RFC 2822 format, the one you see all the time in email messages. Very "as per my last email" of it.--date=shortโ date only, no time, inYYYY-MM-DDformat. Minimalist queen.--date=rawโ shows the date as seconds since the epoch (1970-01-01 00:00:00 UTC), then a space, then the timezone as an offset from UTC (a+or-with four digits; the first two are hours, and the second two are minutes). I.e., as if the timestamp were formatted withstrftime("%s %z"). Lowkey important: the-localoption does not affect the seconds-since-epoch value (which is always measured in UTC), but it does switch the accompanying timezone value. Sneaky but slay.--date=humanโ shows the timezone if the timezone doesn't match the current time-zone, and doesn't print the whole date if that matches (ie skip printing year for dates that are "this year", but also skip the whole date itself if it's in the last few days and we can just say what weekday it was). For older dates the hour and minute is also omitted. It's the "girl, you know when" of date formats ๐ซถ--date=unixโ date as a Unix epoch timestamp (seconds since 1970). Same energy as--raw: this is always in UTC and therefore-localhas no effect.--date=format:<format>โ feeds the<format>to your systemstrftime, except for%s,%z, and%Z, which are handled internally. Use--date=format:%cto show the date in your system locale's preferred format. Peep thestrftime(3)manual for a complete list of format placeholders. And when using-local, the correct syntax is--date=format-local:<format>โ write that down โจ--date=defaultโ the default format, based onctime(3)output. It shows a single line with three-letter day of the week, three-letter month, day-of-month, hour-minute-seconds in"HH:MM:SS"format, followed by 4-digit year, plus timezone information, unless the local time zone is used, e.g.Thu Jan 1 00:00:00 1970 +0000. Classic, iconic, the moment.
--parentsโ print also the parents of the commit (in the form"commit parent..."). Also enables parent rewriting, see History Simplification above. Family tree behavior ๐--childrenโ print also the children of the commit (in the form"commit child..."). Also enables parent rewriting, see History Simplification above. Now we're going down the tree, obsessed.--left-rightโ mark which side of a symmetric difference a commit is reachable from. Commits from the left side are prefixed with<and those from the right with>. If combined with--boundary, those commits are prefixed with-.
For example, if you have this topology:
y---b---b branch B
/ \ /
/ .
/ / \
o---x---a---a branch A
you would get an output like this:
$ git rev-list --left-right --boundary --pretty=oneline A...B
>bbbbbbb... 3rd on b
>bbbbbbb... 2nd on b
<aaaaaaa... 3rd on a
<aaaaaaa... 2nd on a
-yyyyyyy... 1st on b
-xxxxxxx... 1st on a
Not the < and > turning into arrows, I can't ๐ญ it's giving annotated map.
--graphโ draw a text-based graphical representation of the commit history on the left hand side of the output. This may cause extra lines to be printed in between commits, in order for the graph history to be drawn properly. Cannot be combined with--no-walkโ those two do NOT sit together at lunch, periodt.
This enables parent rewriting, see History Simplification above.
This implies the --topo-order option by default, but the --date-order option may also be specified. So it picks a fave but you're allowed to swap.
--show-linear-break[=<barrier>]โ when--graphis not used, all history branches are flattened which can make it hard to see that the two consecutive commits do not belong to a linear branch. This option puts a barrier in between them in that case. If<barrier>is specified, it is the string that will be shown instead of the default one. Custom barrier string?? main character energy honestly.--graph-lane-limit=<n>โ when--graphis used, limit the number of graph lanes to be shown. Lanes over the limit are replaced with a truncation mark~. By default it is set to0(no limit), zero and negative values are ignored and treated as no limit. So yeah,0and the negatives are all just "no limit", don't overthink it ๐ง--no-graph-indent,--graph-indentโ when used with--graph, indent visual roots (commits with no parents or whose parents are not shown) to differentiate them from commits that are vertically adjacent but unrelated. Enabled by default. Use--no-graph-indentto disable or setlog.graphIndentto set a default preference. The roots get their own little space, as they deserve ๐
๐ธ PRETTY FORMATS ๐ธ
Ok so if the commit is a merge, and if the pretty-format is not oneline, email or raw, an additional line is inserted before the Author: line. This line begins with "Merge: " and the hashes of ancestral commits are printed, separated by spaces. Big caveat bestie: note that the listed commits may not necessarily be the list of the direct parent commits if you have limited your view of history โ for example, if you are only interested in changes related to a certain directory or file. So like, don't @ me when the list looks weird, it's doing what you asked.
There are several built-in formats, and you can define additional formats by setting a pretty.<name> config option to either another format name, or a format: string, as described below (see git-config(1)). Here are the details of the built-in formats, get comfy:
oneline
<hash> <title-line>
This is designed to be as compact as possible. Snack-sized. A little bite.
short
commit <hash>
Author: <author>
<title-line>
medium
commit <hash>
Author: <author>
Date: <author-date>
<title-line>
<full-commit-message>
full
commit <hash>
Author: <author>
Commit: <committer>
<title-line>
<full-commit-message>
fuller
commit <hash>
Author: <author>
AuthorDate: <author-date>
Commit: <committer>
CommitDate: <committer-date>
<title-line>
<full-commit-message>
reference
<abbrev-hash> (<title-line>, <short-author-date>)
This format is used to refer to another commit in a commit message and is the same as --pretty='format:%C(auto)%h (%s, %ad)'. By default, the date is formatted with --date=short unless another --date option is explicitly specified. As with any format: with format placeholders, its output is not affected by other options like --decorate and --walk-reflogs. It minds its own business, respectfully ๐
email
From <hash> <date>
From: <author>
Date: <author-date>
Subject: [PATCH] <title-line>
<full-commit-message>
mboxrd
Like email, but lines in the commit message starting with "From " (preceded by zero or more ">") are quoted with ">" so they aren't confused as starting a new commit. Escaping the imposters, we love to see it ๐
raw
The raw format shows the entire commit exactly as stored in the commit object. Notably, the hashes are displayed in full, regardless of whether --abbrev or --no-abbrev are used, and parents information show the true parent commits, without taking grafts or history simplification into account. Note that this format affects the way commits are displayed, but not the way the diff is shown e.g. with git log --raw. To get full object names in a raw diff format, use --no-abbrev. No filter, no edits, just the truth โจ
format:<format-string>
The format:<format-string> format allows you to specify which information you want to show. It works a little bit like printf format, with the notable exception that you get a newline with %n instead of \n. That trips everyone up, so like, noted ๐
E.g, format:"The author of %h was %an, %ar%nThe title was >>%s<<%n" would show something like this:
The author of fe6e0ee was Junio C Hamano, 23 hours ago
The title was >>t4119: test autocomputing -p<n> for traditional diff input.<<
The placeholders are:
- Placeholders that expand to a single literal character:
%nโ newline%%โ a raw%%x00โ%xfollowed by two hexadecimal digits is replaced with a byte with the hexadecimal digits' value (we will call this "literal formatting code" in the rest of this document).
- Placeholders that affect formatting of later placeholders:
%Credโ switch color to red%Cgreenโ switch color to green%Cblueโ switch color to blue%Cresetโ reset color%C(<spec>)โ color specification, as described under Values in the "CONFIGURATION FILE" section ofgit-config(1). By default, colors are shown only when enabled for log output (bycolor.diff,color.ui, or--color, and respecting theautosettings of the former if we are going to a terminal).%C(auto,<spec>)is accepted as a historical synonym for the default (e.g.,%C(auto,red)). Specifying%C(always,<spec>)will show the colors even when color is not otherwise enabled (though consider just using--color=alwaysto enable color for the whole output, including this format and anything else git might color).autoalone (i.e.%C(auto)) will turn on auto coloring on the next placeholders until the color is switched again.%mโ left (<), right (>) or boundary (-) mark%w([<w>[,<i1>[,<i2>]]])โ switch line wrapping, like the-woption ofgit-shortlog(1).
okay so the padding girlies deserve their own moment because this is where your format string starts doing architecture ๐ โจ
%<(<n>[,(trunc|ltrunc|mtrunc)])โ makes the next placeholder take at least<n>column widths, padding spaces on the right if it needs to. Optionally you can truncate (with an ellipsis..) at the left (ltrunc) giving you..ft, in the middle (mtrunc) giving youmi..le, or at the end (trunc) giving yourig.., whenever the output is longer than<n>columns. Note 1: truncating only works correctly when<n> >= 2. Note 2: spaces around the<n>and<m>(see below) values are optional. Note 3: emojis and other wide characters take two display columns, which may over-run column boundaries (yes, the irony of an emoji breaking your alignment is not lost on me ๐ญ). Note 4: decomposed character combining marks may be misplaced at padding boundaries.%<|(<m> )โ makes the next placeholder take at least up to the<m>th display column, padding spaces on the right if necessary. Negative<m>values measure column positions from the right hand edge of the terminal window.%>(<n>),%>|(<m>)โ same energy as%<(<n>)and%<|(<m>)respectively, but padding spaces on the left instead.%>>(<n>),%>>|(<m>)โ same as%>(<n>)and%>|(<m>)respectively, except that if the next placeholder takes more spaces than given and there are spaces on its left, it uses those spaces instead.%><(<n>),%><|(<m>)โ same as%<(<n>)and%<|(<m>)respectively, but it pads both sides, i.e. the text is centered. main character alignment, honestly ๐
โจ placeholders that expand to info extracted from the commit โจ
this is the good stuff, buckle up bestie ๐ซถ
%Hโ commit hash%hโ abbreviated commit hash%Tโ tree hash%tโ abbreviated tree hash%Pโ parent hashes%pโ abbreviated parent hashes%anโ author name%aNโ author name (respecting.mailmap, seegit-shortlog(1)orgit-blame(1))%aeโ author email%aEโ author email (respecting.mailmap, seegit-shortlog(1)orgit-blame(1))%alโ author email local-part (the part before the@sign)%aLโ author local-part (see%al) respecting.mailmap, seegit-shortlog(1)orgit-blame(1)%adโ author date (format respects the--date=option)%aDโ author date, RFC2822 style%arโ author date, relative%atโ author date, UNIX timestamp%aiโ author date, ISO 8601-like format%aIโ author date, strict ISO 8601 format%asโ author date, short format (YYYY-MM-DD)%ahโ author date, human style (like the--date=humanoption ofgit-rev-list(1))%cnโ committer name%cNโ committer name (respecting.mailmap, seegit-shortlog(1)orgit-blame(1))%ceโ committer email%cEโ committer email (respecting.mailmap, seegit-shortlog(1)orgit-blame(1))%clโ committer email local-part (the part before the@sign)%cLโ committer local-part (see%cl) respecting.mailmap, seegit-shortlog(1)orgit-blame(1)%cdโ committer date (format respects the--date=option)%cDโ committer date, RFC2822 style%crโ committer date, relative%ctโ committer date, UNIX timestamp%ciโ committer date, ISO 8601-like format%cIโ committer date, strict ISO 8601 format%csโ committer date, short format (YYYY-MM-DD)%chโ committer date, human style (like the--date=humanoption ofgit-rev-list(1))%dโ ref names, like the--decorateoption ofgit-log(1)%Dโ ref names without the" ("and")"wrapping%(count)โ the number of a patch within a patch series. Used only in--commit-list-formatinformat-patch%(total)โ the total number of patches in a patch series. Used only in--commit-list-formatinformat-patch
the fancy custom ones ๐
%(decorate[:<option>,...])โ ref names with custom decorations. Thedecoratestring may be followed by a colon and zero or more comma-separated options. Option values may contain literal formatting codes โ and those must be used for commas (%x2C) and closing parentheses (%x29), because of their role in the option syntax. iykyk ๐prefix=<value>โ shown before the list of ref names. Defaults to" (".suffix=<value>โ shown after the list of ref names. Defaults to")".separator=<value>โ shown between ref names. Defaults to", ".pointer=<value>โ shown betweenHEADand the branch it points to, if any. Defaults to" โ ".tag=<value>โ shown before tag names. Defaults to"tag: ".
For example, to produce decorations with no wrapping or tag annotations, and spaces as separators:
%(decorate:prefix=,suffix=,tag=,separator= )
%(describe[:<option>,...])โ human-readable name, likegit-describe(1); empty string for commits that can't be described. Thedescribestring may be followed by a colon and zero or more comma-separated options. Heads up: descriptions can be inconsistent when tags are added or removed at the same time. ๐ฌtags[=<bool-value>]โ instead of only considering annotated tags, consider lightweight tags as well.abbrev=<number>โ instead of using the default number of hexadecimal digits (which varies according to the number of objects in the repository, with a default of7), use<number>digits โ or as many digits as needed to form a unique object name.match=<pattern>โ only consider tags matching the givenglob(7)<pattern>, excluding therefs/tags/prefix.exclude=<pattern>โ do not consider tags matching the givenglob(7)<pattern>, excluding therefs/tags/prefix.
%Sโ ref name given on the command line by which the commit was reached (likegit log --source), only works withgit log%eโ encoding%sโ subject%fโ sanitized subject line, suitable for a filename%bโ body%Bโ raw body (unwrapped subject and body)%Nโ commit notes%GGโ raw verification message from GPG for a signed commit%G?โ shows"G"for a good (valid) signature,"B"for a bad signature,"U"for a good signature with unknown validity,"X"for a good signature that has expired,"Y"for a good signature made by an expired key,"R"for a good signature made by a revoked key,"E"if the signature cannot be checked (e.g. missing key) and"N"for no signature%GSโ shows the name of the signer for a signed commit%GKโ shows the key used to sign a signed commit%GFโ shows the fingerprint of the key used to sign a signed commit%GPโ shows the fingerprint of the primary key whose subkey was used to sign a signed commit%GTโ shows the trust level for the key used to sign a signed commit
reflog besties ๐ง
%gDโ reflog selector, e.g.refs/stash@{1}orrefs/stash@{2 minutes ago}; the format follows the rules described for the-goption. The portion before the@is the refname as given on the command line (sogit log -g refs/heads/masterwould yieldrefs/heads/master@{0}).%gdโ shortened reflog selector; same as%gD, but the refname portion is shortened for human readability (sorefs/heads/masterbecomes justmaster).%gnโ reflog identity name%gNโ reflog identity name (respecting.mailmap, seegit-shortlog(1)orgit-blame(1))%geโ reflog identity email%gEโ reflog identity email (respecting.mailmap, seegit-shortlog(1)orgit-blame(1))%gsโ reflog subject
%(trailers[:<option>,...])โ display the trailers of the body as interpreted bygit-interpret-trailers(1). Thetrailersstring may be followed by a colon and zero or more comma-separated options. If any option is provided multiple times, the last occurrence wins. ๐key=<key>โ only show trailers with the specified<key>. Matching is done case-insensitively and the trailing colon is optional. If the option is given multiple times, trailer lines matching any of the keys are shown. This option automatically enables theonlyoption so that non-trailer lines in the trailer block are hidden. If that's not what you want, it can be disabled withonly=false. E.g.,%(trailers:key=Reviewed-by)shows trailer lines with keyReviewed-by.only[=<bool>]โ select whether non-trailer lines from the trailer block should be included.
okay so %(trailers:...) has its own little options menu, and here is every single knob on it, no skips:
separator=<sep>โ specify the separator inserted between trailer lines. Defaults to a line feed character. The string<sep>may contain the literal formatting codes described above. To use comma as separator one must use%x2Cas it would otherwise be parsed as next option. E.g.,%(trailers:key=Ticket,separator=%x2C )shows all trailer lines whose key isTicketseparated by a comma and a space.unfold[=<bool>]โ make it behave as ifinterpret-trailer's--unfoldoption was given. E.g.,%(trailers:only,unfold=true)unfolds and shows all trailer lines.keyonly[=<bool>]โ only show the key part of the trailer.valueonly[=<bool>]โ only show the value part of the trailer.key_value_separator=<sep>โ specify the separator inserted between the key and value of each trailer. Defaults to": ". Otherwise it shares the same semantics asseparator=<sep>above.
Note ๐ซถ Some placeholders may depend on other options given to the revision traversal engine. For example, the%g*reflog options will insert an empty string unless we are traversing reflog entries (e.g., bygit log -g). The%dand%Dplaceholders will use the"short"decoration format if--decoratewas not already provided on the command line.
The boolean options accept an optional value [=<bool-value>]. The values taken by --type=bool git-config(1), like yes and off, are all accepted. Giving a boolean option without =<value> is equivalent to giving it with =true. easy โจ
And now, the modifier era โ these tiny characters after the % are so underrated:
- If you add a
+(plus sign) after%of a placeholder, a line-feed is inserted immediately before the expansion if and only if the placeholder expands to a non-empty string. - If you add a
-(minus sign) after%of a placeholder, all consecutive line-feeds immediately preceding the expansion are deleted if and only if the placeholder expands to an empty string. - If you add a
' '(space) after%of a placeholder, a space is inserted immediately before the expansion if and only if the placeholder expands to a non-empty string.
๐ฆ tformat: ๐ฆ
The tformat: format works exactly like format:, except that it provides "terminator" semantics instead of "separator" semantics. In other words, each commit has the message terminator character (usually a newline) appended, rather than a separator placed between entries. This means that the final entry of a single-line format will be properly terminated with a new line, just as the "oneline" format does. For example:
$ git log -2 --pretty=format:%h 4da45bef \
| perl -pe '$_ .= " -- NO NEWLINE\n" unless /\n/'
4da45be
7134973 -- NO NEWLINE
$ git log -2 --pretty=tformat:%h 4da45bef \
| perl -pe '$_ .= " -- NO NEWLINE\n" unless /\n/'
4da45be
7134973
In addition, any unrecognized string that has a % in it is interpreted as if it has tformat: in front of it. For example, these two are equivalent:
$ git log -2 --pretty=tformat:%h 4da45bef
$ git log -2 --pretty=%h 4da45bef
๐ DIFF FORMATTING ๐
By default, git log does not generate any diff output. The options below can be used to show the changes made by each commit. that's your glow-up switch ๐
Note that unless one of--diff-mergesvariants (including short-m,-c,--cc, and--ddoptions) is explicitly given, merge commits will not show a diff, even if a diff format like--patchis selected, nor will they match search options like-S. The exception is when--first-parentis in use, in which case first-parent is the default format for merge commits. ๐ญ read that twice bestie, it's the classic gotcha.
-p,-u,--patchโ Generate patch (see the section called โGENERATING PATCH TEXT WITH -Pโ).-s,--no-patchโ Suppress all output from the diff machinery. Useful for commands likegit showthat show the patch by default to squelch their output, or to cancel the effect of options like--patch,--statearlier on the command line in an alias.-mโ Show diffs for merge commits in the default format. This is similar to--diff-merges=on, except-mwill produce no output unless-pis given as well.-cโ Produce combined diff output for merge commits. Shortcut for--diff-merges=combined -p.--ccโ Produce dense combined diff output for merge commits. Shortcut for--diff-merges=dense-combined -p.--ddโ Produce diff with respect to first parent for both merge and regular commits. Shortcut for--diff-merges=first-parent -p.--remerge-diffโ Produce remerge-diff output for merge commits. Shortcut for--diff-merges=remerge -p.--no-diff-mergesโ Synonym for--diff-merges=off.
๐ --diff-merges=<format> ๐
Specify diff format to be used for merge commits. Default is f unless --first-parent is in use, in which case first-parent is the default.
The following formats are supported:
off,noneโ Disable output of diffs for merge commits. Useful to override implied value.on,mโ Make diff output for merge commits to be shown in the default format. The default format can be changed usinglog.diffMergesconfiguration variable, whose default value isseparate.first-parent,1โ Show full diff with respect to first parent. This is the same format as--patchproduces for non-merge commits.separateโ Show full diff with respect to each of parents. Separate log entry and diff is generated for each parent.combined,cโ Show differences from each of the parents to the merge result simultaneously instead of showing pairwise diff between a parent and the result one at a time. Furthermore, it lists only files which were modified from all parents.dense-combined,ccโ Further compress output produced by--diff-merges=combinedby omitting uninteresting hunks whose contents in the parents have only two variants and the merge result picks one of them without modification.remerge,rโ Remerge two-parent merge commits to create a temporary tree objectโpotentially containing files with conflict markers and such. A diff is then shown between that temporary tree and the actual merge commit.
โ ๏ธ The output emitted when this option is used is subject to change, and so is its interaction with other options (unless explicitly documented). So likeโฆ don't build your whole personality on it, iykyk ๐
--combined-all-pathsโ Cause combined diffs (used for merge commits) to list the name of the file from all parents. It thus only has effect when--diff-merges=[dense-]combinedis in use, and is likely only useful if filename changes are detected (i.e. when either rename or copy detection have been requested).-U<n>,--unified=<n>โ Generate diffs with<n>lines of context. The number of context lines defaults todiff.contextor3if the configuration variable is unset. (-Uwithout<n>is silently accepted as a synonym for-pdue to a historical accident). Implies--patch. historical accident ๐ iconic honestly--output=<file>โ Output to a specific file instead of stdout.--output-indicator-new=<char>,--output-indicator-old=<char>,--output-indicator-context=<char>โ Specify the character used to indicate new, old or context lines in the generated patch. Normally they are+,-and' 'respectively.--rawโ For each commit, show a summary of changes using the raw diff format. See the โRAW OUTPUT FORMATโ section ofgit-diff(1). This is different from showing the log itself in raw format, which you can achieve with--format=raw.--patch-with-rawโ Synonym for-p --raw.-tโ Show the tree objects in the diff output.--indent-heuristicโ Enable the heuristic that shifts diff hunk boundaries to make patches easier to read. This is the default. ๐--no-indent-heuristicโ Disable the indent heuristic.--minimalโ Spend extra time to make sure the smallest possible diff is produced.--patienceโ Generate a diff using the โpatience diffโ algorithm.--histogramโ Generate a diff using the โhistogram diffโ algorithm.--anchored=<text>โ Generate a diff using the โanchored diffโ algorithm.
This option may be specified more than once.
If a line exists in both the source and destination, exists only once, and starts with <text>, this algorithm attempts to prevent it from appearing as a deletion or addition in the output. It uses the โpatience diffโ algorithm internally. it's giving main character energy for one specific line โจ
๐ง --diff-algorithm=(patience|minimal|histogram|myers) ๐ง
Choose a diff algorithm. The variants are as follows:
default,myersโ The basic greedy diff algorithm. Currently, this is the default.minimalโ Spend extra time to make sure the smallest possible diff is produced.patienceโ Use โpatience diffโ algorithm when generating patches.histogramโ This algorithm extends the patience algorithm to โsupport low-occurrence common elementsโ.
For instance, if you configured the diff.algorithm variable to a non-default value and want to use the default one, then you have to use --diff-algorithm=default option. the config does NOT care about your feelings ๐ญ
โญ --stat[=<width>[,<name-width>[,<count>]]] โญ
Generate a diffstat. By default, as much space as necessary will be used for the filename part, and the rest for the graph part. Maximum width defaults to terminal width, or 80 columns if not connected to a terminal, and can be overridden by <width>. The width of the filename part can be limited by giving another width <name-width> after a comma or by setting diff.statNameWidth=<name-width>. The width of the graph part can be limited by using --stat-graph-width=<graph-width> or by setting diff.statGraphWidth=<graph-width>. Using --stat or --stat-graph-width affects all commands generating a stat graph, while setting diff.statNameWidth or diff.statGraphWidth does not affect git format-patch. By giving a third parameter <count>, you can limit the output to the first <count> lines, followed by ... if there are more. numbers!! widths!! the whole buffet ๐
--stat-width=<width>,--stat-name-width=<name-width>,--stat-count=<count>โ the same three knobs, but you can totally set each one individually instead of doing the whole<width>,<name-width>,<count>combo platter ๐๏ธ
--compact-summaryโ gives you a condensed lil summary of the extended header tea โ file creations or deletions (shown as"new"or"gone", and optionally+lif it's a symlink ๐) plus mode changes (+xor-xfor adding or removing the executable bit respectively) โ all stuffed into the diffstat. It lands right between the filename part and the graph part. Also, heads up: this implies--statโจ--numstatโ basically--stat's cousin, except it shows the number of added and deleted lines in decimal notation and the pathname with no abbreviation, so it's way more machine-friendly ๐ค. And for binary files? It just spits out two-instead of saying0 0. iconic.--shortstatโ only wants the last line of the--statformat, bestie. That's the total number of modified files, plus how many lines got added and deleted. Short and sweet ๐-X [<param>,...],--dirstat[=<param>,...]โ shows you the distribution of the relative amount of changes for each sub-directory ๐๏ธ. You can customize how--dirstatbehaves by passing it a comma-separated list of parameters. The defaults are controlled by thediff.dirstatconfig variable (peepgit-config(1)). Here's the menu of parameters:changesโ computes the dirstat numbers by counting the lines removed from the source, or added to the destination. This ignores the amount of pure code movement inside a file โ like, rearranging lines in a file doesn't count as much as other changes. This is the default behavior when you give no parameter at all.linesโ computes the dirstat numbers by doing the regular line-based diff analysis and summing up the removed/added line counts. (For binary files it counts 64-byte chunks instead, since binary files have no natural concept of lines, obviously ๐ซ ). This is a more expensive--dirstatbehavior thanchanges, but it does count rearranged lines within a file as much as other changes. The resulting output is consistent with what you get from the other--*statoptions.filesโ computes the dirstat numbers by counting the number of files changed. Every changed file counts equally in the dirstat analysis. This is the computationally cheapest--dirstatbehavior, since it doesn't have to look at the file contents at all. lazy girl summer behavior and honestly? valid.cumulativeโ counts changes in a child directory for the parent directory too. โ ๏ธ Note that when you usecumulative, the sum of the percentages reported may exceed 100%. The default (non-cumulative) behavior can be specified with thenoncumulativeparameter.<limit>โ an integer parameter that specifies a cut-off percent (3% by default). Directories contributing less than this percentage of the changes simply don't show up in the output. gone girl, not invited.
Example time ๐ โ the following will count changed files, while ignoring directories with less than 10% of the total amount of changed files, and accumulating child directory counts in the parent directories:
--dirstat=files,10,cumulative
--cumulativeโ a synonym for--dirstat=cumulative. short king.--dirstat-by-file[=<param>,...]โ a synonym for--dirstat=files,<param>,.... also short king.--summaryโ outputs a condensed summary of extended header info such as creations, renames and mode changes ๐--patch-with-statโ a synonym for-p --stat. yes that's it, that's the whole vibe.-zโ separates the commits with NULs instead of newlines ๐ซถ
Also, when --raw or --numstat has been given, it does not munge pathnames and uses NULs as output field terminators.
Without this option, pathnames with "unusual" characters get quoted, as explained for the config variable core.quotePath (see git-config(1)).
--name-onlyโ shows only the name of each changed file in the post-image tree. The file names are often encoded in UTF-8. For more info, see the discussion about encoding in thegit-log(1)manual page ๐--name-statusโ shows only the name(s) and status of each changed file. See the description of the--diff-filteroption for what those status letters actually mean. Just like--name-only, the file names are often encoded in UTF-8 ๐ท๏ธ--submodule[=<format>]โ tells Git how to show differences in submodules. When you specify--submodule=short, the short format is used โ it just shows the names of the commits at the beginning and end of the range. When you specify--submoduleor--submodule=log, the log format is used, which lists the commits in the range likegit-submodule(1)summarydoes. And when you specify--submodule=diff, the diff format is used โ it shows an inline diff of the changes in the submodule contents between the commit range ๐ฎโ๐จ. Defaults todiff.submodule, or the short format if that config option isn't set.--color[=<when>]โ show colored diff ๐.--color(i.e. without=<when>) is the same as--color=always.<when>can be one ofalways,never, orauto.--no-colorโ turns off colored diff entirely. It's the same as--color=never๐--color-moved[=<mode>]โ moved lines of code get colored differently โจ. The<mode>defaults tonoif you don't give the option at all, and tozebraif you give the option with no mode. The mode must be one of:noโ moved lines are not highlighted. boring but honest.defaultโ a synonym forzebra. โ ๏ธ This may change to a more sensible mode in the future, so don't get too attached.plainโ any line added in one location and removed in another location gets colored withcolor.diff.newMoved. Similarly,color.diff.oldMovedis used for removed lines that are added somewhere else in the diff. This mode picks up any moved line, but ngl it's not super useful in a review when you're trying to figure out if a block of code was moved without permutation.blocksโ blocks of moved text of at least 20 alphanumeric characters are detected greedily ๐. The detected blocks are painted using either thecolor.diff.(old|new)Movedcolor. Fair warning: adjacent blocks cannot be told apart.zebraโ blocks of moved text are detected as inblocksmode. The blocks are painted using either thecolor.diff.(old|new)Movedcolor orcolor.diff.(old|new)MovedAlternative. The change between the two colors indicates that a new block was detected ๐ฆdimmed-zebraโ similar tozebra, but with additional dimming of the uninteresting parts of moved code. The bordering lines of two adjacent blocks are considered interesting, the rest is uninteresting. Alsodimmed_zebrais a deprecated synonym โ old news, bestie.
--no-color-movedโ turns off move detection. You can use this to override configuration settings. It's the same as--color-moved=no๐ โโ๏ธ--color-moved-ws=<mode>,...โ configures how whitespace is ignored when performing move detection for--color-moved. These modes can be given as a comma-separated list:noโ do not ignore whitespace when performing move detection.ignore-space-at-eolโ ignore changes in whitespace at EOL.ignore-space-changeโ ignore changes in the amount of whitespace. This ignores whitespace at line end, and considers all other sequences of one or more whitespace characters to be equivalent.ignore-all-spaceโ ignore whitespace when comparing lines. This ignores differences even if one line has whitespace where the other line has none.allow-indentation-changeโ initially ignore any whitespace in the move detection, then group the moved code blocks into a block only if the change in whitespace is the same per line. โ ๏ธ This is incompatible with the other modes, so pick a lane.
--no-color-moved-wsโ do not ignore whitespace when performing move detection. You can use this to override configuration settings. It's the same as--color-moved-ws=no๐ซ--word-diff[=<mode>]โ by default, words are delimited by whitespace; see--word-diff-regexbelow. The<mode>defaults toplain, and must be one of:colorโ highlight changed words using only colors. Implies--color๐จplainโ show words as[-removed-]and{added}. It makes no attempts to escape the delimiters if they appear in the input, so the output may be ambiguous ๐ญporcelainโ use a special line-based format intended for script consumption. Added/removed/unchanged runs are printed in the usual unified diff format, starting with a+,-, orcharacter at the beginning of the line and extending to the end of the line. Newlines in the input are represented by a tilde~on a line of its own.noneโ disable word diff again. we're so back / we're so done.
Note that despite the name of the first mode, color is used to highlight the changed parts in all modes if enabled ๐
The --word-diff option operates by taking the same line-by-line diff that's produced without the option, and computing word-by-word changes within each hunk. This may produce a larger diff than a dedicated word-diff tool would ๐ซ . If Git acquires a different implementation in the future, the output may change. Note that this is similar to the --diff-algorithm option, which may also change the output. iykyk.
--word-diff-regex=<regex>โ use<regex>to decide what a word is, instead of considering runs of non-whitespace to be a word. Also implies--word-diffunless it was already enabled.
Every non-overlapping match of the <regex> is considered a word. Anything between these matches is considered whitespace and ignored(!) for the purposes of finding differences. You may want to append |[^[:space:]] to your regular expression to make sure it matches all non-whitespace characters. โ ๏ธ A match that contains a newline is silently truncated(!) at the newline โ sneaky.
For example, --word-diff-regex=. will treat each character as a word and, correspondingly, show differences character by character ๐.
The regex can also be set via a diff driver or configuration option โ see gitattributes(5) or git-config(1). Giving it explicitly overrides any diff driver or configuration setting. Diff drivers override configuration settings. hierarchy matters, bestie ๐
--color-words[=<regex>]โ equivalent to--word-diff=colorplus (if a regex was specified)--word-diff-regex=<regex>โจ--no-renamesโ bestie, this one just turns rename detection off. Like fully off, even if your config file is like "no babe default to detecting renames". Nope. Not today. ๐--rename-empty,--no-rename-emptyโ controls whether empty blobs are allowed to be used as a rename source. That's it, that's the whole vibe check. โจ--checkโ this one's your lil safety bestie ๐ซถ โ it warns you if your changes introduce conflict markers or whitespace errors. And what counts as a "whitespace error"? That's controlled by thecore.whitespaceconfiguration. By default the culprits are: trailing whitespaces (including lines that are nothing but whitespace ๐ญ) and a space character that's immediately followed by a tab character inside the initial indent of the line. If it finds problems it exits with a non-zero status. Also heads up: it's not compatible with--exit-code, so don't try to serve both at once.--ws-error-highlight=<kind>โ highlights whitespace errors in the context, old or new lines of the diff. Multiple values get separated by comma,noneresets previous values,defaultresets the list tonew, andallis shorthand forold,new,context. When you don't pass this option anddiff.wsErrorHighlightconfig isn't set either, only whitespace errors in new lines get highlighted. The errors get colored withcolor.diff.whitespace๐--full-indexโ instead of showing just the first handful of characters, this shows the full pre- and post-image blob object names on theindexline when it's generating patch format output. No abbreviating, we're showing the whole thing, periodt.--binaryโ on top of--full-index, this outputs a binary diff that can actually be applied withgit-apply. Implies--patch. ๐ฅ--abbrev[=<n>]โ instead of showing the full 40-byte hexadecimal object name in diff-raw format output and diff-tree header lines, show the shortest prefix that's at least<n>hexdigits long that uniquely refers to the object. In diff-patch output format though,--full-indextakes higher precedence โ i.e. if--full-indexis specified, full blob names get shown regardless of--abbrev. Non default number of digits can be specified with--abbrev=<n>.-B[<n>][/<m>],--break-rewrites[=[<n>][/<m>]]โ this breaks complete rewrite changes into pairs of delete and create. It serves two purposes, bestie:
It affects the way a change that amounts to a total rewrite of a file โ not as a series of deletion and insertion mixed together with a very few lines that happen to match textually as the context, but as a single deletion of everything old followed by a single insertion of everything new. The number <m> controls this aspect of the -B option (defaults to 60%). -B/70% specifies that less than 30% of the original should remain in the result for Git to consider it a total rewrite (i.e. otherwise the resulting patch will be a series of deletion and insertion mixed together with context lines).
When used with -M, a totally-rewritten file is also considered as the source of a rename (usually -M only considers a file that disappeared as the source of a rename), and the number <n> controls this aspect of the -B option (defaults to 50%). -B20% specifies that a change with addition and deletion compared to 20% or more of the file's size are eligible for being picked up as a possible source of a rename to another file. ๐
-M[<n>],--find-renames[=<n>]โ if it's generating diffs, this detects and reports renames for each commit. For following files across renames while traversing history, see--follow(different tool, different vibe). If<n>is specified, it's a threshold on the similarity index (i.e. amount of addition/deletions compared to the file's size). For example,-M90%means Git should consider a delete/add pair to be a rename if more than 90% of the file hasn't changed. Without a%sign, the number gets read as a fraction, with a decimal point before it. I.e.-M5becomes0.5, and is thus the same as-M50%. Similarly,-M05is the same as-M5%. To limit detection to exact renames, use-M100%. The default similarity index is50%. โจ-C[<n>],--find-copies[=<n>]โ detects copies as well as renames. See also--find-copies-harder. If<n>is specified, it has the same meaning as for-M<n>.--find-copies-harderโ okay so for performance reasons, by default the-Coption only finds copies if the original file of the copy was modified in the same changeset. This flag makes the command inspect unmodified files as candidates for the source of copy. Heads up though: this is a very expensive operation for large projects, so use it with caution ๐ญ Giving more than one-Coption has the same effect.-D,--irreversible-deleteโ omits the preimage for deletes, i.e. it prints only the header but not the diff between the preimage and/dev/null.
The resulting patch is not meant to be applied withpatchorgit applyโ this is solely for people who want to just concentrate on reviewing the text after the change. In addition, the output obviously lacks enough information to apply such a patch in reverse, even manually, hence the name of the option. ๐
When used together with -B, it also omits the preimage in the deletion part of a delete/create pair.
-l<num>โ so the-Mand-Coptions involve some preliminary steps that can detect subsets of renames/copies cheaply, followed by an exhaustive fallback portion that compares all remaining unpaired destinations to all relevant sources. (For renames, only remaining unpaired sources are relevant; for copies, all original sources are relevant.) For N sources and destinations, this exhaustive check isO(N^2). This option prevents that exhaustive portion of rename/copy detection from running if the number of source/destination files involved exceeds the specified number. Defaults todiff.renameLimit. Note that a value of0is treated as unlimited.--diff-filter=[(A|C|D|M|R|T|U|X|B)...[*]]โ selects only files that are Added (A), Copied (C), Deleted (D), Modified (M), Renamed (R), have their Type (i.e. regular file, symlink, submodule, ...) changed (T), are Unmerged (U), are UnknowX (X... okay it's Unknown ๐ญ), or have had their pairing Broken (B). Any combination of the filter characters (including none) can be used. When*(All-or-none) is added to the combination, all paths are selected if there is any file that matches other criteria in the comparison; if there is no file that matches other criteria, nothing is selected.
Also, these upper-case letters can be downcased to exclude. E.g. --diff-filter=ad excludes added and deleted paths. ๐
Note that not all diffs can feature all types. For instance, copied and renamed entries cannot appear if detection for those types is disabled.
-S<string>โ looks 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's 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>โ looks for differences whose patch text contains added/removed lines that match<regex>.
To illustrate the difference between -S<regex> --pickaxe-regex and -G<regex>, consider a commit with the following diff in the same file:
+ return frotz(nitfol, two->ptr, 1, 0);
...
- hit = frotz(nitfol, mf2.ptr, 1, 0);
While git log -G"frotz\(nitfol" will show this commit, git log -S"frotz\(nitfol" --pickaxe-regex will not (because the number of occurrences of that string did not change). ๐
Unless --text is supplied, patches of binary files without a textconv filter will be ignored.
See the pickaxe entry in gitdiffcore(7) for more information.
--find-object=<object-id>โ looks for differences that change the number of occurrences of the specified object. Similar to-S, just the argument is different in that it doesn't search for a specific string but for a specific object id.
The object can be a blob or a submodule commit. It implies the -t option in git-log to also find trees. ๐ธ
--pickaxe-allโ when-Sor-Gfinds a change, this shows all the changes in that changeset, not just the files that contain the change in<string>. Main character energy for the whole commit. ๐--pickaxe-regexโ treats the<string>given to-Sas an extended POSIX regular expression to match.-O<orderfile>โ controls the order in which files appear in the output. This overrides thediff.orderFileconfiguration variable (seegit-config(1)). To canceldiff.orderFile, use-O/dev/null. ๐
The output order is determined by the order of glob patterns in <orderfile>. All files with pathnames that match the first pattern are output first, all files with pathnames that match the second pattern (but not the first) are output next, and so on. All files with pathnames that do not match any pattern are output last, as if there was an implicit match-all pattern at the end of the file. If multiple pathnames have the same rank (they match the same pattern but no earlier patterns), their output order relative to each other is the normal order.
<orderfile> is parsed as follows:
- Blank lines are ignored, so they can be used as separators for readability.
- Lines starting with a hash (
"#") are ignored, so they can be used for comments. Add a backslash ("\") to the beginning of the pattern if it starts with a hash. - Each other line contains a single pattern.
Patterns have the same syntax and semantics as patterns used for fnmatch(3) without the FNM_PATHNAME flag, except a pathname also matches a pattern if removing any number of the final pathname components matches the pattern. For example, the pattern "foo*bar" matches "fooasdfbar" and "foo/bar/baz/asdf" but not "foobarx". ๐ฆ
--skip-to=<file>,--rotate-to=<file>โ discards the files before the named<file>from the output (i.e. skip to), or moves them to the end of the output (i.e. rotate to). Real talk: these options were invented primarily for the use of thegit difftoolcommand, and may not be very useful otherwise. ๐-Rโ swaps the two inputs; that is, shows differences from index or on-disk file to tree contents. Flip it and reverse it. ๐--relative[=<path>],--no-relativeโ okay so if you're chillin' in a subdirectory of the project, this tells git to keep it local: it excludes changes outside that directory and shows pathnames relative to it. โจ And if you're not in a subdirectory (bare repository girlies, this means you), you can straight-up name which subdirectory you want the output relative to by passing a<path>argument.--no-relativeis the uno-reverse card โ it countermands both thediff.relativeconfig option and any previous--relative. ๐-a,--textโ treat all files as text. every single one. no cap. ๐ซถ--ignore-cr-at-eolโ ignore carriage-return at the end of line when it's doing a comparison. lowkey obsessed with this one.--ignore-space-at-eolโ ignore changes in whitespace at EOL (end of line, bestie). ๐ธ-b,--ignore-space-changeโ ignore changes in the amount of whitespace. this one ignores whitespace at line end, and considers all other sequences of one or more whitespace characters to be equivalent. soa banda bare the same vibe. โจ-w,--ignore-all-spaceโ ignore whitespace when comparing lines. and like, fully ignore โ it ignores differences even if one line has whitespace where the other line has none. ๐--ignore-blank-linesโ ignore changes whose lines are all blank. bye empty lines, nobody asked.-I<regex>,--ignore-matching-lines=<regex>โ ignore changes whose all lines match<regex>. this option may be specified more than once, so stack 'em if you need to. ๐--inter-hunk-context=<number>โ show the context between diff hunks, up to the specified<number>of lines, thereby fusing hunks that are close to each other (they were meant to be together, fr). defaults todiff.interHunkContext, or0if that config option is unset.-W,--function-contextโ show the whole function as context lines for each change. main character function energy ๐. the function names are determined in the same way asgit diffworks out patch hunk headers โ see "Defining a custom hunk-header" ingitattributes(5).--ext-diffโ allow an external diff helper to be executed. so like, if you set an external diff driver withgitattributes(5), you need to use this option withgit-log(1)and friends. don't forget it, bestie. ๐ฅ--no-ext-diffโ disallow external diff drivers. the opposite. periodt.--textconv,--no-textconvโ allow (or disallow) external text conversion filters to be run when comparing binary files. seegitattributes(5)for the details. and here's the important bit: because textconv filters are typically a one-way conversion, the resulting diff is suitable for human consumption but cannot be applied. ๐ญ for this reason, textconv filters are enabled by default only forgit-diff(1)andgit-log(1)โ but not forgit-format-patch(1)or diff plumbing commands.--ignore-submodules[=(none|untracked|dirty|all)]โ ignore changes to submodules in the diff generation.allis the default. here's the breakdown, iykyk:noneโ considers the submodule modified when it either contains untracked or modified files, or its HEAD differs from the commit recorded in the superproject. can be used to override any settings of the ignore option ingit-config(1)orgitmodules(5).untrackedโ submodules are not considered dirty when they only contain untracked content (but they are still scanned for modified content).dirtyโ ignores all changes to the work tree of submodules; only changes to the commits stored in the superproject are shown (this was the behavior until1.7.0, vintage ๐ ).allโ hides all changes to submodules.
--src-prefix=<prefix>โ show the given source<prefix>instead of"a/". ๐ฆ--dst-prefix=<prefix>โ show the given destination<prefix>instead of"b/". matching set, adorable.--no-prefixโ do not show any source or destination prefix. clean, minimal, no clutter.--default-prefixโ use the default source and destination prefixes ("a/"and"b/"). this overrides configuration variables such asdiff.noprefix,diff.srcPrefix,diff.dstPrefix, anddiff.mnemonicPrefix(seegit-config(1)). so it just snaps everything back to factory settings. โจ--line-prefix=<prefix>โ prepend an additional<prefix>to every line of output. every. single. line. ๐--ita-invisible-in-indexโ okay so by default, entries added bygit add -Nappear as an existing empty file ingit diffand a new file ingit diff --cached. this option makes the entry appear as a new file ingit diffand non-existent ingit diff --cached. it can be reverted with--ita-visible-in-index. both options are experimental and could be removed in future โ so like, don't build your whole personality on them. ๐--max-depth=<depth>โ for each pathspec given on the command line, descend at most<depth>levels of directories. a value of-1means no limit. cannot be combined with wildcards in the pathspec. given a tree containingfoo/bar/baz, the following list shows the matches generated by each set of options:--max-depth=0 -- foo:foo--max-depth=1 -- foo:foo/bar--max-depth=1 -- foo/bar:foo/bar/baz--max-depth=1 -- foo foo/bar:foo/bar/baz--max-depth=2 -- foo:foo/bar/baz
if no pathspec is given, the depth is measured as if all top-level entries were specified. note that this is different than measuring from the root, in that --max-depth=0 would still return foo. this allows you to still limit depth while asking for a subset of the top-level entries. ๐ง
โ ๏ธ note that this option is only supported for diffs between tree objects โ not against the index or working tree. don't try it, it's giving heartbreak.
for more detailed explanation on these common options, see also gitdiffcore(7). ๐
๐ GENERATING PATCH TEXT WITH -P ๐
okay so running git-diff(1), git-log(1), git-show(1), git-diff-index(1), git-diff-tree(1), or git-diff-files(1) with the -p option produces patch text. and you can customize the creation of that patch text via the GIT_EXTERNAL_DIFF and the GIT_DIFF_OPTS environment variables (see git(1)), plus the diff attribute (see gitattributes(5)). ๐ซถ
and here's the tea: what the -p option produces is slightly different from the traditional diff format. let's go through it:
- It is preceded by a
"git diff"header that looks like this:
diff --git a/file1 b/file2
the a/ and b/ filenames are the same unless rename/copy is involved. especially, even for a creation or a deletion, /dev/null is not used in place of the a/ or b/ filenames. so like, don't expect it. ๐
when a rename/copy is involved, file1 and file2 show the name of the source file of the rename/copy and the name of the file that the rename/copy produces, respectively. โจ
- It is followed by one or more extended header lines:
old mode <mode>
new mode <mode>
deleted file mode <mode>
new file mode <mode>
copy from <path>
copy to <path>
rename from <path>
rename to <path>
similarity index <number>
dissimilarity index <number>
index <hash>..<hash> <mode>
file modes <mode> are printed as 6-digit octal numbers including the file type and file permission bits. ๐ข
path names in extended headers do not include the a/ and b/ prefixes.
the similarity index is the percentage of unchanged lines, and the dissimilarity index is the percentage of changed lines. it's a rounded down integer, followed by a percent sign. so the similarity index value of 100% is thus reserved for two equal files, while 100% dissimilarity means that no line from the old file made it into the new one. ๐ iconic, honestly.
the index line includes the blob object names before and after the change. the <mode> is included if the file mode does not change; otherwise, separate lines indicate the old and the new mode.
- Pathnames with
"unusual"characters are quoted as explained for the configuration variablecore.quotePath(seegit-config(1)). ๐ฆ - All the
file1files in the output refer to files before the commit, and all thefile2files refer to files after the commit. it is incorrect to apply each change to each file sequentially. for example, this patch will swapaandb:
diff --git a/a b/b
rename from a
rename to b
diff --git a/b b/a
rename from b
rename to a
yeah. it's a whole thing. don't do the sequential apply thing, it's a trap. ๐ญ
- Hunk headers mention the name of the function to which the hunk applies. see "Defining a custom hunk-header" in
gitattributes(5)for details of how to tailor this to specific languages. ๐ธ
๐ COMBINED DIFF FORMAT ๐
Okay so any diff-generating command can take the -c or --cc option and it'll spit out a combined diff when it's showing you a merge. This is literally the default format when showing merges with git-diff(1) or git-show(1). Also note โ you can hand a suitable --diff-merges option to any of these commands to force diffs to be generated in a specific format. Flex option, honestly. ๐
A "combined diff" format looks like this:
diff --combined describe.c
index fabadb8,cc95eb0..4866510
--- a/describe.c
+++ b/describe.c
@@@ -98,20 -98,12 +98,20 @@@
return (a_date > b_date) ? -1 : (a_date == b_date) ? 0 : 1;
}
- static void describe(char *arg)
-static void describe(struct commit *cmit, int last_one)
++static void describe(char *arg, int last_one)
{
+ unsigned char sha1[20];
+ struct commit *cmit;
struct commit_list *list;
static int initialized = 0;
struct commit_name *n;
+ if (get_sha1(arg, sha1) < 0)
+ usage(describe_usage);
+ cmit = lookup_commit_reference(sha1);
+ if (!cmit)
+ usage(describe_usage);
+
if (!initialized) {
initialized = 1;
for_each_ref(get_name);
So here's the breakdown, bestie, step by step:
- It's preceded by a "git diff" header that looks like this (when the
-coption is used):
diff --combined file
or like this (when the --cc option is used):
diff --cc file
- It's followed by one or more extended header lines (this example shows a merge with two parents):
index <hash>,<hash>..<hash>
mode <mode>,<mode>..<mode>
new file mode <mode>
deleted file mode <mode>,<mode>
The mode <mode>,<mode>..<mode> line appears only if at least one of the <mode> is different from the rest. Extended headers with info about detected content movement (renames and copying detection) are designed to work with the diff of two <tree-ish> and are not used by combined diff format. Periodt.
- It's followed by a two-line from-file/to-file header:
--- a/file
+++ b/file
Similar to the two-line header for the traditional unified diff format, /dev/null is used to signal created or deleted files. โจ
However, if the --combined-all-paths option is provided, instead of a two-line from-file/to-file you get an N+1 line from-file/to-file header, where N is the number of parents in the merge commit:
--- a/file
--- a/file
--- a/file
+++ b/file
This extended format can be useful if rename or copy detection is active, to allow you to see the original name of the file in different parents. Kind of iconic of it tbh ๐ฆ
- Chunk header format is modified to prevent people from accidentally feeding it to
patch -p1. Combined diff format was created for review of merge commit changes, and was not meant to be applied. The change is similar to the change in the extended index header:
@@@ <from-file-range> <from-file-range> <to-file-range> @@@
There are (number of parents + 1) @ characters in the chunk header for combined diff format. Math! ๐งฎ
Unlike the traditional unified diff format, which shows two files A and B with a single column that has - (minus โ appears in A but removed in B), + (plus โ missing in A but added to B), or " " (space โ unchanged) prefix, this format compares two or more files file1, file2,... with one file X, and shows how X differs from each of fileN. One column for each of fileN is prepended to the output line to note how X's line is different from it. Slay, more columns. ๐
A - character in the column N means that the line appears in fileN but it does not appear in the result. A + character in the column N means that the line appears in the result, and fileN does not have that line (in other words, the line was added, from the point of view of that parent).
In the above example output, the function signature was changed from both files (hence two - removals from both file1 and file2, plus ++ to mean one line that was added does not appear in either file1 or file2). Also, eight other lines are the same from file1 but do not appear in file2 (hence prefixed with +). See, it all makes sense ๐
When shown by git diff-tree -c, it compares the parents of a merge commit with the merge result (i.e. file1..fileN are the parents). When shown by git diff-files -c, it compares the two unresolved merge parents with the working tree file (i.e. file1 is stage 2 aka "our version", file2 is stage 3 aka "their version"). iykyk ๐ซถ
๐ธ EXAMPLES ๐ธ
git log --no-merges
Show the whole commit history, but skip any merges. No merge drama in this group chat ๐
git log v2.6.12.. include/scsi drivers/scsi
Show all commits since version v2.6.12 that changed any file in the include/scsi or drivers/scsi subdirectories. Very targeted, we love a specific queen ๐
git log --since="2 weeks ago" -- gitk
Show the changes during the last two weeks to the file gitk. The -- is necessary to avoid confusion with the branch named gitk. Don't skip it, seriously ๐
git log --name-status release..test
Show the commits that are in the "test" branch but not yet in the "release" branch, along with the list of paths each commit modifies. Receipts, basically ๐งพ
git log --follow builtin/rev-list.c
Shows the commits that changed builtin/rev-list.c, including those commits that occurred before the file was given its present name. It remembers the before-times โจ
git log --branches --not --remotes=origin
Shows all commits that are in any of local branches but not in any of remote-tracking branches for origin (what you have that origin doesn't). Main character energy vs. the remote ๐
git log master --not --remotes=*/master
Shows all commits that are in local master but not in any remote repository master branches. Same vibe, wildcard edition ๐
git log -p -m --first-parent
Shows the history including change diffs, but only from the "main branch" perspective, skipping commits that come from merged branches, and showing full diffs of changes introduced by the merges. This makes sense only when following a strict policy of merging all topic branches when staying on a single integration branch. Very specific setup, respect it ๐
git log -L '/int main/',/^}/:main.c
Shows how the function main() in the file main.c evolved over time. Character development arc, honestly ๐ฆ
git log -3
Limits the number of commits to show to 3. Sometimes you just want a little snack, not the whole buffet ๐
๐ DISCUSSION ๐
Git is to some extent character encoding agnostic. Wild, I know.
- The contents of the blob objects are uninterpreted sequences of bytes. There is no encoding translation at the core level. None. Zero. Zip. ๐ โโ๏ธ
- Path names are encoded in UTF-8 normalization form C. This applies to tree objects, the index file, ref names, as well as path names in command line arguments, environment variables and config files (
.git/config(seegit-config(1)),gitignore(5),gitattributes(5)andgitmodules(5)).
Note that Git at the core level treats path names simply as sequences of non-NUL bytes, there are no path name encoding conversions (except on Mac and Windows). Therefore, using non-ASCII path names will mostly work even on platforms and file systems that use legacy extended ASCII encodings. However, repositories created on such systems will not work properly on UTF-8-based systems (e.g. Linux, Mac, Windows) and vice versa. Additionally, many Git-based tools simply assume path names to be UTF-8 and will fail to display other encodings correctly. So like... proceed with caution bestie ๐
- Commit log messages are typically encoded in UTF-8, but other extended ASCII encodings are also supported. This includes ISO-8859-x, CP125x and many others, but not UTF-16/32, EBCDIC and CJK multi-byte encodings (GBK, Shift-JIS, Big5, EUC-x, CP9xx etc.). Not those, okay? ๐ธ
Although we encourage that the commit log messages are encoded in UTF-8, both the core and Git Porcelain are designed not to force UTF-8 on projects. If all participants of a particular project find it more convenient to use legacy encodings, Git does not forbid it. It's giving "you do you" ๐ However, there are a few things to keep in mind:
git commitandgit commit-treeissue a warning if the commit log message given to it does not look like a valid UTF-8 string, unless you explicitly say your project uses a legacy encoding. The way to say this is to havei18n.commitEncodingin.git/configfile, like this:
[i18n]
commitEncoding = ISO-8859-1
Commit objects created with the above setting record the value of i18n.commitEncoding in their encoding header. This is to help other people who look at them later. Lack of this header implies that the commit log message is encoded in UTF-8. Considerate icon behavior ๐
git log,git show,git blameand friends look at theencodingheader of a commit object, and try to re-code the log message into UTF-8 unless otherwise specified. You can specify the desired output encoding withi18n.logOutputEncodingin.git/configfile, like this:
[i18n]
logOutputEncoding = ISO-8859-1
If you do not have this configuration variable, the value of i18n.commitEncoding is used instead. Fallback queen ๐
Note that we deliberately chose not to re-code the commit log message when a commit is made to force UTF-8 at the commit object level, because re-coding to UTF-8 is not necessarily a reversible operation. So don't come for that design choice, it's load-bearing ๐ญ
๐ธ CONFIGURATION ๐ธ
okay bestie, this is the config era of the page ๐
head over to git-config(1) for the core variables, and git-diff(1) for anything to do with generating diffs. those are your girls.
โจ format.pretty
the default for the --format option. (peep Pretty Formats above, it's literally right there โฌ๏ธ) defaults to medium.
โจ i18n.logOutputEncoding
the encoding used when displaying logs. (see Discussion above, no cap.) defaults to the value of i18n.commitEncoding if that's set, and UTF-8 otherwise. cute and simple ๐
โจ log.abbrevCommit
if true, it makes git-log(1), git-show(1), and git-whatchanged(1) assume --abbrev-commit. you can override it with --no-abbrev-commit whenever you feel like it, queen ๐
โจ log.date
sets the default date-time mode for the log command. setting a value for log.date is basically the same as using git log's --date option โ see git-log(1) for the deets.
if the format is set to "auto:foo" and the pager is in use, format "foo" will be used for the date format. otherwise, "default" gets used. it's giving adaptive โจ
โจ log.decorate
prints out the ref names of any commits that the log command shows. possible values are:
short
the ref name prefixes refs/heads/, refs/tags/ and refs/remotes/ are not printed.
full
the full ref name (including prefix) are printed.
auto
if the output is going to a terminal, the ref names are shown as if short were given, otherwise no ref names are shown at all.
this is the same as the --decorate option of the git log. iykyk ๐ฆ
โจ log.initialDecorationSet
by default, git log only shows decorations for certain known ref namespaces. if all is specified, then it shows all refs as decorations. main character energy for every ref, honestly ๐
โจ log.excludeDecoration
excludes the specified patterns from the log decorations. this is similar to the --decorate-refs-exclude command-line option, but heads up: the config option can be overridden by the --decorate-refs option. so the command line wins, as always ๐
โจ log.diffMerges
sets the diff format to be used when --diff-merges=on is specified โ see --diff-merges in git-log(1) for details. defaults to separate.
โจ log.follow
if true, git log will act as if the --follow option was used when a single <path> is given. it has the same limitations as --follow, i.e. it cannot be used to follow multiple files. one path only, bestie, that's the rule ๐ซถ
โจ log.graphColors
a list of colors, separated by commas, that can be used to draw history lines in git log --graph. aesthetic history lines, we love to see it ๐
โจ log.graphIndent
if true, indent visual roots when rendering the graphs with --graph. set to true by default. it can be overriden with --[no-]graph-indent.
โจ log.showRoot
if true, the initial commit will be shown as a big creation event. it's equivalent to a diff against an empty tree. tools like git-log(1) or git-whatchanged(1), which normally hide the root commit, will now show it. true by default. the origin story deserves screen time honestly ๐ฑ
โจ log.showSignature
if true, it makes git-log(1), git-show(1), and git-whatchanged(1) assume --show-signature. signatures on, periodt โ๏ธ
โจ log.mailmap
if true, it makes git-log(1), git-show(1), and git-whatchanged(1) assume --use-mailmap, otherwise they assume --no-use-mailmap. true by default.
โจ notes.mergeStrategy
which merge strategy to choose by default when resolving notes conflicts. must be one of manual, ours, theirs, union, or cat_sort_uniq. defaults to manual. see the "NOTES MERGE STRATEGIES" section of git-notes(1) for more info on each strategy โ she did her homework ๐
this setting can be overridden by passing the --strategy option to git-notes(1).
โจ notes.<name>.mergeStrategy
which merge strategy to choose when doing a notes merge into refs/notes/<name>. this overrides the more general notes.mergeStrategy. see the "NOTES MERGE STRATEGIES" section in git-notes(1) for more on the available strategies.
โจ notes.displayRef
which ref (or refs, if a glob or specified more than once), in addition to the default set by core.notesRef or GIT_NOTES_REF, to read notes from when showing commit messages with the git log family of commands.
this setting can be overridden with the GIT_NOTES_DISPLAY_REF environment variable, which must be a colon separated list of refs or globs.
a warning will be issued for refs that do not exist, but a glob that does not match any refs is silently ignored. rude but valid ๐
this setting can be disabled by the --no-notes option to the git-log(1) family of commands, or by the --notes=<ref> option accepted by those commands.
the effective value of core.notesRef (possibly overridden by GIT_NOTES_REF) is also implicitly added to the list of refs to be displayed. sneaky little bonus ref ๐
โจ notes.rewrite.<command>
when rewriting commits with <command> (currently amend or rebase), if this variable is false, git will not copy notes from the original to the rewritten commit. defaults to true. see also notes.rewriteRef below.
this setting can be overridden with the GIT_NOTES_REWRITE_REF environment variable, which must be a colon separated list of refs or globs.
โจ notes.rewriteMode
when copying notes during a rewrite (see the notes.rewrite.<command> option), determines what to do if the target commit already has a note. must be one of overwrite, concatenate, cat_sort_uniq, or ignore. defaults to concatenate.
this setting can be overridden with the GIT_NOTES_REWRITE_MODE environment variable.
โจ notes.rewriteRef
when copying notes during a rewrite, specifies the (fully qualified) ref whose notes should be copied. may be a glob, in which case notes in all matching refs will be copied. you may also specify this configuration several times.
no default value bestie โ you must configure this variable to enable note rewriting. set it to refs/notes/commits to enable rewriting for the default commit notes. it will not do it for you, it's not a mind reader ๐ญ
can be overridden with the GIT_NOTES_REWRITE_REF environment variable. see notes.rewrite.<command> above for a further description of its format.
๐ง GIT ๐ง
part of the git(1) suite. one of us, one of us ๐ซถ
and that's a wrap on the whole page, bestie!! ๐โจ you made it to the end, iconic behavior honestly ๐ this was written for Git 2.56.0, dated 2026-09-27. go forth and git log responsibly, mwah ๐
๐ธ
๐ฆ where this page comes from
- arch rolling: git 2.56.0-1 ยท GPL-2.0-only
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms