Top (Comparing and Merging Files)
Next: Overview , Up: (dir) [ Contents ][ Index ] Comparing and Merging Files ¶ This manual is for GNU Diffutils (version 3.12, 12 January 2025), and documents the GNU diff , diff3 , sdiff , and cmp commands for showing the differences between files and the GNU patch command for using their output to update files. Copyright © 1992–1994, 1998, 2001–2002, 2004, 2006, 2009–2025 Free Software Foundation, Inc. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.
A copy of the license is included in the section entitled “GNU Free Documentation License.” Short Table of Contents Overview 1 What Comparison Means 2 diff Output Formats 3 Incomplete Lines 4 Comparing Directories 5 Making diff Output Prettier 6 diff Performance Tradeoffs 7 Comparing Three Files 8 Merging From a Common Ancestor 9 Interactive Merging with sdiff 10 Merging with patch 11 Tips for Making and Using Patches 12 Invoking cmp 13 Invoking diff 14 Invoking diff3 15 Invoking patch 16 Invoking sdiff 17 Standards conformance 18 Future Projects Appendix A Copying This Manual Appendix B Translations of This Manual Appendix C Index Table of Contents Overview 1 What Comparison Means 1.1 Hunks 1.2 Suppressing Differences in Blank and Tab Spacing 1.3 Suppressing Differences Whose Lines Are All Blank 1.4 Suppressing Differences Whose Lines All Match a Regular Expression 1.5 Suppressing Case Differences 1.6 Summarizing Which Files Differ 1.7 Binary Files and Forcing Text Comparisons 1.8 Comparing Files While They Are Changing 2 diff Output Formats 2.1 Two Sample Input Files 2.2 Showing Differences in Their Context 2.2.1 Context Format 2.2.1.1 An Example of Context Format 2.2.1.2 An Example of Context Format with Less Context 2.2.1.3 Detailed Description of Context Format 2.2.2 Unified Format 2.2.2.1 An Example of Unified Format 2.2.2.2 Detailed Description of Unified Format 2.2.3 Showing Which Sections Differences Are in 2.2.3.1 Showing Lines That Match Regular Expressions 2.2.3.2 Showing C Function Headings 2.2.4 Showing Alternate File Names 2.3 Showing Differences Side by Side 2.3.1 Controlling Side by Side Format 2.3.2 An Example of Side by Side Format 2.4 Showing Differences Without Context 2.4.1 An Example of Normal Format 2.4.2 Detailed Description of Normal Format 2.5 Making Edit Scripts 2.5.1 ed Scripts 2.5.1.1 Example ed Script 2.5.1.2 Detailed Description of ed Format 2.5.2 Forward ed Scripts 2.5.3 RCS Scripts 2.6 Merging Files with If-then-else 2.6.1 Line Group Formats 2.6.2 Line Formats 2.6.3 An Example of If-then-else Format 2.6.4 Detailed Description of If-then-else Format 3 Incomplete Lines 4 Comparing Directories 5 Making diff Output Prettier 5.1 Preserving Tab Stop Alignment 5.2 Omitting trailing blanks 5.3 Paginating diff Output 6 diff Performance Tradeoffs 7 Comparing Three Files 7.1 A Third Sample Input File 7.2 An Example of diff3 Normal Format 7.3 Detailed Description of diff3 Normal Format 7.4 diff3 Hunks 8 Merging From a Common Ancestor 8.1 Selecting Which Changes to Incorporate 8.2 Marking Conflicts 8.3 Generating the Merged Output Directly 8.4 How diff3 Merges Incomplete Lines 8.5 Saving the Changed File 9 Interactive Merging with sdiff 9.1 Specifying diff Options to sdiff 9.2 Merge Commands 10 Merging with patch 10.1 Selecting the patch Input Format 10.2 Revision Control 10.3 Applying Imperfect Patches 10.3.1 Applying Patches with Changed White Space 10.3.2 Applying Reversed Patches 10.3.3 Helping patch Find Inexact Matches 10.3.4 Predicting what patch will do 10.4 Creating and Removing Files 10.5 Updating Timestamps on Patched Files 10.6 Multiple Patches in a File 10.7 Applying Patches in Other Directories 10.8 Backup Files 10.9 Backup File Names 10.10 Reject File Names 10.11 Messages and Questions from patch 10.11.1 Controlling the Verbosity of patch 10.11.2 Inhibiting Keyboard Input 10.11.3 patch Quoting Style 10.12 patch and the POSIX Standard 10.13 GNU patch and Traditional patch 11 Tips for Making and Using Patches 11.1 Tips for Patch Producers 11.2 Tips for Patch Consumers 11.3 Avoiding Common Mistakes 11.4 Generating Smaller Patches 12 Invoking cmp 12.1 Options to cmp 13 Invoking diff 13.1 Options to diff 14 Invoking diff3 14.1 Options to diff3 15 Invoking patch 15.1 Options to patch 16 Invoking sdiff 16.1 Options to sdiff 17 Standards conformance 18 Future Projects 18.1 Suggested Projects for Improving GNU diff and patch 18.1.1 Handling Multi-byte and Varying-Width Characters 18.1.2 Handling Changes to the Directory Structure 18.1.3 Files that are Neither Directories Nor Regular Files 18.1.4 File Names that Contain Unusual Characters 18.1.5 Outputting Diffs in Timestamp Order 18.1.6 Ignoring Certain Changes 18.1.7 Improving Performance 18.2 Reporting Bugs Appendix A Copying This Manual Appendix B Translations of This Manual Appendix C Index Next: Overview , Up: (dir) [ Contents ][ Index ]