Overview
diff3 helps resolve merge conflicts by comparing changes between a common ancestor file (BASE) and two modified files (MINE, THEIR). It is especially useful when two users have independently modified the same original file.
Key Features
- Analyzes differences between three files
- Identifies and marks merge conflicts
- Analyzes changes based on the original file (BASE)
- Can output merged results
Key Options
The main options for the diff3 command are used to control the format and content of the comparison results.
Output Format and Merging
Comparison and Filtering
Generated command:
Try combining the commands.
Description:
`diff3` Executes the command.
Combine the above options to virtually execute commands with AI.
Usage Examples
Understand how to compare and merge three files through various usage examples of the diff3 command.
Basic Three-File Comparison
diff3 file1.txt file2.txt file3.txt
Compares the differences between three files: file1.txt (BASE), file2.txt (MINE), and file3.txt (THEIR).
Merge Three Files and Mark Conflicts
diff3 -m original.txt my_version.txt their_version.txt
Merges the three files and outputs conflicts with standard conflict markers. This output can be manually edited to resolve conflicts.
Save Merged Results to a New File
diff3 -m original.txt my_version.txt their_version.txt > merged_file.txt
Saves the merged content to a file named merged_file.txt. This file may contain conflict markers.
Show Only Overlapping Changes
diff3 -x file1.txt file2.txt file3.txt
Displays only the parts that have been changed in all three files, i.e., potential merge conflict points, concisely.
Tips & Precautions
diff3 is a powerful tool, but it is most effective when its characteristics are understood.
Understanding Conflict Markers
The conflict markers outputted when using the diff3 -m option have the following meanings:
- <<<<<<<: Start of the current (MINE) version
- |||||||: Start of the common ancestor (BASE) version
- =======: Separator between the two versions
- >>>>>>>: End of the incoming (THEIR) version
Usage Tips
- **Version Control Systems:** Understanding the principles of diff3 can aid in manual conflict resolution when merge conflicts occur in version control systems like Git.
- **Backups:** It is always advisable to create a backup before merging important files.
- **File Order:** It is common practice to specify files in the order `BASE MINE THEIR` for diff3. Adhering to this order makes interpreting conflict markers easier.