merge
Combine branches in version control systems
SYNOPSIS
merge [OPTIONS] FILE1 BASE FILE2
PARAMETERS
-A, --show-all-dups
Output all conflicts, including those where one file deleted a block and the other modified it. Normally, only conflicts where both files changed the same area are shown.
-E, --diff3-name
Use diff3-style output for conflict markers. This uses a simpler header format than the default.
-L label, --label=label
Use label instead of the filename in the conflict markers (<<<<<<<, >>>>>>>). This option can be specified up to three times to label FILE1, BASE, and FILE2 respectively.
-p, --print-output
Print the merged output to standard output instead of overwriting FILE1.
-q, --quiet
Suppress all warning and error messages.
-V, --version
Output version information and exit.
--help
Display a help message and exit.
DESCRIPTION
The merge command performs a three-way merge of files, taking an original common base file and two modified versions of that base file.
Its primary purpose is to integrate changes from two different branches or versions of a file into a single, unified output. It automatically combines common sections and non-conflicting differences. When conflicts arise (where both modified files change the same section differently), merge marks these sections in the output file with special delimiters (e.g., <<<<<<<, =======, >>>>>>>), requiring manual resolution.
Often used by version control systems like Git and Mercurial as a default or configurable external merge tool. By default, it typically modifies the first input file (FILE1) in-place, but can print the result to standard output.
CAVEATS
merge assumes the three input files are related as described: FILE1 and FILE2 diverged from a common ancestor BASE. Providing unrelated files will likely lead to incorrect or nonsensical merge results.
Automatic merging cannot resolve all conflicts; complex changes require manual intervention by editing the file sections marked with conflict delimiters. The default behavior of overwriting FILE1 can be destructive if not used carefully; consider using the -p option to print to stdout first.
CONFLICT MARKERS
When merge cannot automatically resolve a difference, it inserts special markers into the output file to highlight the conflict. A common conflict block looks like this:
<<<<<<< FILE1
content from FILE1
=======
content from FILE2
>>>>>>> FILE2
The section between <<<<<<< and ======= represents FILE1's version, and the section between ======= and >>>>>>> represents FILE2's version. The user must manually edit this block to resolve the conflict and remove the markers.
HISTORY
The concept of three-way merging is foundational to version control systems. The merge utility, often part of the GNU Diff Utilities (diffutils) package, provides a standard, low-level implementation of this crucial function. It has been a staple in the Unix/Linux environment for decades, predating modern distributed version control systems like Git, but remains relevant as a robust tool for file comparison and merging tasks.