Home Explore Blog CI



git

8th chunk of `Documentation/diff-options.adoc`
ca327fb12233308f568b0aed93abfd79088f6d30509e55ca0000000100000fa3
 renames while traversing history, see
	`--follow`.
endif::git-log[]
	If _<n>_ is specified, it is 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 is to be read as
	a fraction, with a decimal point before it.  I.e., `-M5` becomes
	0.5, and is thus the same as `-M50%`.  Similarly, `-M05` is
	the same as `-M5%`.  To limit detection to exact renames, use
	`-M100%`.  The default similarity index is 50%.

`-C[<n>]`::
`--find-copies[=<n>]`::
	Detect 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`::
	For performance reasons, by default, `-C` option finds copies only
	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.  This is a very expensive operation for large
	projects, so use it with caution.  Giving more than one
	`-C` option has the same effect.

`-D`::
`--irreversible-delete`::
	Omit the preimage for deletes, i.e. print only the header but not
	the diff between the preimage and `/dev/null`. The resulting patch
	is not meant to be applied with `patch` or `git 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`, omit also the preimage in the deletion part
of a delete/create pair.

`-l<num>`::
	The `-M` and `-C` options 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 is O(N^2).  This option
	prevents the exhaustive portion of rename/copy detection from
	running if the number of source/destination files involved
	exceeds the specified number.  Defaults to `diff.renameLimit`.
	Note that a value of 0 is treated as unlimited.

ifndef::git-format-patch[]
`--diff-filter=[(A|C|D|M|R|T|U|X|B)...[*]]`::
	Select 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
	Unknown (`X`), 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>`::
	Look for differences that change the number of occurrences of
	the specified _<string>_ (i.e. addition/deletion) in a file.
	Intended for the scripter's use.
+
It is useful when you're looking for an exact block of code (like a
struct), and want to know the history of that block since it first
came into being: use the feature iteratively to feed the interesting
block in the preimage back into `-S`, and keep going until you get the
very first version of the block.
+
Binary files are searched as well.

`-G<regex>`::
	Look for differences whose patch text contains added/removed
	lines that match _<regex>_.
+
To illustrate the difference between `-S<regex>` `--pickaxe-regex`

Title: Git Diff Options for Rename and Copy Detection, Filtering, and Searching
Summary
This section describes Git diff options for detecting renames and copies, such as `-M` and `-C`, as well as options for filtering diff output, like `--diff-filter`, and searching for specific changes, including `-S` and `-G`, which can be used to customize and refine the diff output to focus on specific types of changes or content.